How to: Disable Foreign Key Constraints with INSERT and UPDATE Statements (Visual Database Tools)

Select the option to disable a foreign key constraint during INSERT and UPDATE transactions if you know that new data will violate the constraint or if the constraint applies only to the data already in the database.

To disable a foreign key constraint for INSERT and UPDATE statements

  1. In Object Explorer, right-click the table with the constraint, and click Design.

    The table opens in Table Designer.

  2. From the Table Designer menu, click Relationships.

  3. In the Foreign Key Relationships dialog box, select the relationship in the Selected Relationship list.

  4. In the grid, click Delete Rule or Update Rule and choose an action from the drop-down list box to the left of the property.

    • No Action   An error message tells the user that the deletion is not allowed and the DELETE is rolled back.

    • Cascade   Deletes all rows containing data involved in the foreign key relationship.

    • Set Null   Sets the value to null if all foreign key columns for the table can accept null values. Applies to SQL Server 2005 only.

    • Set Default   Sets the value to the default value defined for the column if all foreign key columns for the table have defaults defined for them. Applies to SQL Server 2005 only.

Note

If you plan to use triggers to implement database operations, you must disable foreign key constraints in order for the trigger to run.