Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FeniXb3/7122905 to your computer and use it in GitHub Desktop.
Save FeniXb3/7122905 to your computer and use it in GitHub Desktop.
Disable and re-enable all constraints on database in T-SQL. Reference - http://stackoverflow.com/a/161410/1816426
-- disable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
-- enable all constraints - the print is optional
exec sp_msforeachtable @command1="print '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment