MS SQL Server 2005, 2008 – How to set unique constraint for a column

Published on Author bloggerone

Here is how to set unique constraint for a column in Microsoft SQL Server 2005, 2008 to 2012.

Using SQL:

 ALTER TABLE <tablename>
ADD CONSTRAINT <constraintname>
UNIQUE NONCLUSTERED ( <columnname> ) 

See the full syntax here.

In SQL Server Management Studio Express:

  • Right-click table, choose Modify or Design(For Later Versions)
  • Right-click field, choose Indexes/Keys…
  • Click Add
  • For Columns, select the field name you want to be unique.
  • For Type, choose Unique Key.
  • Click CloseSave the table.