hemtros
9/25/2015 - 6:34 PM

Disable and enable foreign key constraints in a database so that we can clean the database

Disable and enable foreign key constraints in a database so that we can clean the database

-- disable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

-- enable all constraints
exec sp_msforeachtable @command1="print '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"