Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Constraint
Message
De
02/03/2004 07:36:24
 
 
À
01/03/2004 22:38:26
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Maintenance bases de données
Titre:
Divers
Thread ID:
00882232
Message ID:
00882293
Vues:
21
>If nType = 1 then CCN can have duplicate entries but if nType = 2 then it cannot.

define a computed field and a unique index for it:
combine_check_fields with CASE WHEN conditionUnique THEN constant ELSE PrimaryKey END

A trace:
CREATE TABLE [dbo].[testTable] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[nType] [tinyint] NOT NULL ,
	[cnn] [char] (1) COLLATE Latin1_General_BIN NOT NULL ,
	[checkunique] AS ([cnn] + case when ([nType] = 2) then (space(10)) else (convert(char(10),[id])) end) 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[testTable] ADD 
	CONSTRAINT [IX_testTable] UNIQUE  NONCLUSTERED 
	(
		[checkunique]
	)  ON [PRIMARY]+
GO
Fabio
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform