Skip to content

Instantly share code, notes, and snippets.

@bvanskiver
Created January 19, 2015 12:53
Show Gist options
  • Save bvanskiver/fde79ed437da4d036481 to your computer and use it in GitHub Desktop.
Save bvanskiver/fde79ed437da4d036481 to your computer and use it in GitHub Desktop.
Disable all foreign key constraints
-- Disables all FK constraints
exec sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'
-- Enables all FK constraints
exec sp_msforeachtable '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