Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Constraint
Message
From
02/03/2004 07:36:24
 
 
To
01/03/2004 22:38:26
General information
Forum:
Microsoft SQL Server
Category:
Database management
Title:
Miscellaneous
Thread ID:
00882232
Message ID:
00882293
Views:
20
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform