Creating and Modifying PRIMARY KEY Constraints

A single PRIMARY KEY constraint can be:

When a PRIMARY KEY constraint is added to an existing column or columns in the table, Microsoft® SQL Server™ checks the existing data in the columns to ensure that the existing data follows the rules for primary keys:

If a PRIMARY KEY constraint is added to a column that has duplicate or null values, SQL Server returns an error and does not add the constraint. It is not possible to add a PRIMARY KEY constraint that violates these rules.

SQL Server automatically creates a unique index to enforce the uniqueness requirement of the PRIMARY KEY constraint. If a clustered index does not already exist on the table, or a nonclustered index is not explicitly specified, a unique, clustered index is created to enforce the PRIMARY KEY constraint.


Important A PRIMARY KEY constraint cannot be deleted if it is being referenced by a FOREIGN KEY constraint in another table; the FOREIGN KEY constraint must be deleted first.


To create a PRIMARY KEY constraint when creating a table

         

To create or delete a PRIMARY KEY constraint on an existing table

         

To modify a PRIMARY KEY constraint

See Also

Primary Key Constraints

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.