How to enable and disable constraints in SQL Server

— Disable all foreign key constraints

EXEC sp_MSforeachtable “ALTER TABLE ? NOCHECK CONSTRAINT ALL”

— Enable all foreign key constraints

EXEC sp_MSforeachtable “ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL”

This entry was posted in MSSQLServer on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply