Creating a Unique Constraint
Create a
- 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.
To create a unique constraint
- In your database diagram, right-click the table that will contain the constraint, then select Properties from the shortcut menu.
-or-
Open the Table Designer for the table that will contain the constraint, right-click in the Table Designer, and choose Properties from the shortcut menu.
- Choose the Indexes/Keys tab.
- Choose New. A system-assigned name appears in the Index name box.
- Under Column name, expand the list of columns and select the column that you want to attach the constraint to. To attach the constraint to multiple columns, select the additional columns in subsequent rows.
- Select the Create UNIQUE check box.
- Select the Constraint option.
The unique constraint is created in the database when you save the table or the diagram.
If you are using SQL Server, you can control the sort order of key values and the action taken when duplicate keys exist. To do this, you should create a unique
See Also
Constraints | Creating a Unique Index | Deleting a Unique Constraint | Unique Constraints