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”

Unknown's avatar

Author: 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

Discover more from SmartTechWays - Innovative Solutions for Smart Businesses

Subscribe now to keep reading and get access to the full archive.

Continue reading