Creating and Modifying FOREIGN KEY Constraints

FOREIGN KEY constraints can be:

When a FOREIGN KEY constraint is added to an existing column or columns in the table, Microsoft® SQL Server™ by default checks the existing data in the columns to ensure that all values, except NULL, exist in the column(s) of the referenced PRIMARY KEY or UNIQUE constraint. However, SQL Server can be prevented from checking the data in the column against the new constraint and made to add the new constraint regardless of the data in the column. This option  is useful when the existing data already meets the new FOREIGN KEY constraint, or when a business rule requires the constraint to be enforced only from this point forward.

However, you should be careful when adding a constraint without checking existing data because this bypasses the controls in SQL Server that enforce the data integrity of the table.

Disabling FOREIGN KEY Constraints

Existing FOREIGN KEY constraints can be disabled for:

Delete a FOREIGN KEY constraint, thus removing the requirement, to enforce referential integrity between the foreign key columns and the related primary key (or UNIQUE constraint) columns in another table.

To create a FOREIGN KEY constraint when creating a table

         

To create a FOREIGN KEY constraint on an existing table

         

To prevent checking of existing data when creating a FOREIGN KEY constraint

         

To modify a FOREIGN KEY constraint

To disable a FOREIGN KEY constraint for INSERT and UPDATE statements

         

To disable a FOREIGN KEY constraint for replication

         

To delete a FOREIGN KEY constraint

         

See Also

Foreign Key Constraints

  


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