Skip to content

Instantly share code, notes, and snippets.

@alantsai
Last active June 1, 2020 09:58
Show Gist options
  • Save alantsai/f551d0f445e616647ff5bca558d2e4ba to your computer and use it in GitHub Desktop.
Save alantsai/f551d0f445e616647ff5bca558d2e4ba to your computer and use it in GitHub Desktop.
[disable sql constraints (foregin key)] how to disable all sql contraints or goregin key - use for import data #sql
-- disable all constraints
EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
-- enable all constraints
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