Quick Reminder: How to Disable and Enable All Foreign Key Constraints in Database

This is one of those things I don't do that often (it just doesn't seem like a good idea) so I always have to look it up.

To disable all your constraints, use the following:

EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

To endable all constraints, use the following:

EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"


Comments

Popular posts from this blog

Using Reference Aliases

List of Visual Studio Keyboard Shortcuts