views:

185

answers:

2

Preferably I would like to know how to do it using the SQL Server Management Studio interface but that isn't completely necessary. If you simply have a script to add one after a table is made that would be fine.

+2  A: 

Try this:

ALTER TABLE dbo.YourTableName 
ADD CONSTRAINT
ConstraintName UNIQUE NONCLUSTERED
(
    Column01,
    Column02,
    Column03
)

I use business names for constraints so that if it is violated and an exception bubbles up, I get "Only one Dept per Employee violation" in my error message rather than "ConstraintXXX violation".

Raj More
+1  A: 
marc_s
Cool. It seems strange that this is in the indexes section instead of the constraints section
Joe Philllips
A Unique Constraint is basically handled by a Unique Index - that's why.
marc_s