It’s a short memo how to do this operations for one or many constraints, and for one or all tables in a database. It concerns both to ordinary check constraints and foreign keys.
1. One constraint
1 |
ALTER TABLE Clients NOCHECK CONSTRAINT CK_Clients_ClientName_Length; |
2. All constraints in one table
1 |
ALTER TABLE Clients NOCHECK CONSTRAINT ALL; |
3. All constraints in all tables
1 |
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' |
For enabling constraint(s) change NOCHECK to WITH CHECK CHECK literally. “WITH CHECK” means that SQL Server should verify all existing rows for that constraint.