Enable and Disable Foreign key and Check constraint in SQL Server

In this post, I demonstrate script to enable and disable foreign key and check constraint in SQL Server.

During data migration and testing purpose, Database Developer requires to disable Foreign key constraint or Check constraint.

Once you disable constraint, then later you might require to enable again, but during this exercise make sure that all your data changes are correct and as per the constraint rule otherwise you cannot enable those constraints.

You can perform disable / enable action only on Foreign Key and Check Constraint.
You cannot perform disable / enable on Primary Key and Unique Key.

Disable All Foreign key and Check Constraint:

Enable All Foreign key and Check Constraint:
Disable all table constraints:
Enable all table constraints:
Disable single constraint:
Enable single constraint:
Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of