Disable all constraints

Sometimes you just need to disable all constraints on a database. Maybe you’re doing some massive data inserts or updates, and the constraints slow it down. Or maybe you just like living dangerously.

Don’t try this at home…

-- Disable all
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'

-- Enable all
EXEC sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'