1

I need to create a unique constraint based on two columns.

How do I achieve that in SQL Server 2008 Express edition?

2 Answers 2

2
ALTER TABLE dbo.YourTable
ADD CONSTRAINT YourConstraintName UNIQUE (Column1, Column2)
Sign up to request clarification or add additional context in comments.

Comments

0
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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.