By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

Conditional Constraints on table columns

P: 6
Guys,

Does SQL Server allow for creating conditional constraints on the table columns?

My table is:

CREATE TABLE [X]
(

[UID] [int] IDENTITY (1, 1) NOT NULL ,
[A] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CS_AS NOT NULL ,
[b] [bit] NOT NULL ,


CONSTRAINT [PK_X] PRIMARY KEY CLUSTERED
(

[UID]

) ON [PRIMARY]

) ON [PRIMARY]

I want to add the following constraints:

CONSTRAINT [IX_UNIQUE1] UNIQUE NONCLUSTERED

(
A, B = 1

) ON [PRIMARY]

CONSTRAINT [IX_UNIQUE2] UNIQUE NONCLUSTERED

(
UPPER(A), B = 0

) ON [PRIMARY]



That is, if the table contains "Hello" in column A, then an insert of ("hello", 1) will be rejected, but ("hello", 0) will be inserted.

Any ideas?

Thanks a lot
Nov 28 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.