How can foreign key constraints be temporarily disabled using T-SQL?

If you want to disable all constraints in the database just run this code: — disable all constraints EXEC sp_MSforeachtable “ALTER TABLE ? NOCHECK CONSTRAINT all” To switch them back on, run: (the print is optional of course and it is just listing the tables) — enable all constraints exec sp_MSforeachtable @command1=”print ‘?'”, @command2=”ALTER TABLE … Read more