Reputation: 3975
I need to create a unique constraint based on two columns.
How do I achieve that in SQL Server 2008 Express edition?
Upvotes: 1
Views: 127
Reputation: 9629
ALTER TABLE mytable
ADD CONSTRAINT myconstraint UNIQUE NONCLUSTERED (
Col1,
Col2
) ON [PRIMARY]
or if you prefer with an index:
CREATE UNIQUE NONCLUSTERED INDEX myindex ON mytable (
Col1,
Col2
) ON [PRIMARY]
Upvotes: 0
Reputation: 755471
ALTER TABLE dbo.YourTable
ADD CONSTRAINT YourConstraintName UNIQUE (Column1, Column2)
Upvotes: 2