By far the simplest method to disable all table constraints on a SQL Server table is to use the ALTER TABLE method, for example if we had a table called MyOrderLines and we wished to disable all the constraints for the table we could run the below command against the table in TSQL.
ALTER TABLE MyOrderLines NOCHECK CONSTRAINT ALL
The above line will disable all constraints and then to re-enable the constraints you can run the below command again via TSQL.
ALTER TABLE MyOrderLines CHECK CONSTRAINT ALL
This will then enable the constrains on the table again so all new record changes will be checked against the constraint or constraints. However when you re-enable a constraint it won’t automatically check the integrity of the existing data in the table, so one option we have available to us is to tell SQL Server when it re-enables the constraint to go and validate the integrity of the existing data against the constraint rules, we can do this by using the below command which tells SQL to check the check constraint.
ALTER TABLE MyOrderLines CHECK CHECK CONSTRAINT ALL
If you only wanted to enable or disable a single or a named constraint then you can change the ALL to be the constraint name.