SQL Server: Disable All Constraints - YAGNI



SQL Server: Disable All Constraints

May 3, 2011 © Kramii (filed under SQL Server)

To disable all constraints on all tables in a database:


EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

To enable all constraints on all tables in a database:


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

Be Sociable, Share!

Share Freely

You are welcome to share this with your friends.
Be Sociable, Share!
Leave a comment »


Leave a Reply

Your email address will not be published. Required fields are marked *