Disabling SQL Server constraints and deleting all rows in tables

16 Jul
2013

— Disable all the constraints in database
EXEC sp_msforeachtable “ALTER TABLE ? NOCHECK CONSTRAINT all”

EXEC sp_msforeachtable “delete from ? ”

— Enable all the constraints in database
EXEC sp_msforeachtable “ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all”

Be Sociable, Share!

Comment Form

You must be logged in to post a comment.

top