SQL Server 2005 How Create a Unique Constraint? SQL Server 2005 How Create a Unique Constraint? sql-server sql-server

SQL Server 2005 How Create a Unique Constraint?


The SQL command is:

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

See the full syntax here.

If you want to do it from a Database Diagram:

  • right-click on the table and select 'Indexes/Keys'
  • click the Add button to add a new index
  • enter the necessary info in the Properties on the right hand side:
    • the columns you want (click the ellipsis button to select)
    • set Is Unique to Yes
    • give it an appropriate name


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 Close, Save the table.


ALTER TABLE [TableName] ADD CONSTRAINT  [constraintName] UNIQUE ([columns])