Skip to content

Instantly share code, notes, and snippets.

@jdu
Created August 3, 2012 03:05
Show Gist options
  • Save jdu/3243962 to your computer and use it in GitHub Desktop.
Save jdu/3243962 to your computer and use it in GitHub Desktop.
Disable/Enable Foreign Key Constraints for DB migrations [SQL Server]
# Disable
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
# Enable
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