How to: Create Unique Constraints
Create a unique constraint to ensure no duplicate values are entered in specific columns that do not participate in a primary key. While both a unique constraint and a primary key enforce uniqueness, you should attach a unique constraint instead of a primary key constraint to a table if:
You want to enforce uniqueness in a column or combination of columns. You can attach multiple unique constraints to a table, whereas you can attach only one primary key constraint to a table.
You want to enforce uniqueness in a column that allows null values. You can attach unique constraints to columns that allow null values, whereas you can attach primary key constraints only to columns that do not allow null values. When you attach a unique constraint to a column allowing null values, you ensure that at most one row will have a null value in the constrained column.
Note
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.
To create a unique constraint
In Server Explorer, select the table to which you want to add a unique constraint, and from the Database menu click Open Table Definition.
The table opens in Table Designer.
From the Table Designer menu, click Indexes/Keys.
In the Indexes/Keys dialog box, click Add.
In the grid, click Type and choose Unique Key from the drop-down list box to the right of the property.
The unique constraint is created in the database when you save the table.
See Also
Tasks
How to: Delete Unique Constraints
Concepts
Unique Constraints (Visual Database Tools)
Reference
Primary or Unique Key Properties