Temporarily disabling foreign key constraints in SQL Server

Goal: Is to temporarily disable all foreign key constraint and later enable the Constraint again?

Solutions

-- Disable all the constraint in database EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

-- Enable all the constraint in database EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"

New on Geeks with Blogs