Quantcast
Channel: Greg – code.commongroove.com
Viewing all articles
Browse latest Browse all 30

T-SQL: Disable Constraint Checks On All Tables With A Single Line Query

$
0
0

Microsoft’s “undocumented” but quite useful stored procedure, sp_msforeachtable, you can easily disable constraint checks on all tables in a database. Here’s how:

EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

To re-enable the checks after you are done, simply change NOCHECK to CHECK, e.g.

EXEC sp_msforeachtable "ALTER TABLE ? CHECK CONSTRAINT all"

Hope this helps!


Viewing all articles
Browse latest Browse all 30

Trending Articles