Created
March 4, 2015 11:09
-
-
Save tompazourek/8cfd9862dcd7fd3b1bb7 to your computer and use it in GitHub Desktop.
Truncate all tables in the database. Source: http://stackoverflow.com/a/12719464/108374
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' | |
exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL' | |
exec sp_MSforeachtable 'DELETE FROM ?' | |
exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL' | |
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL' | |
exec sp_MSforeachtable 'IF NOT EXISTS (SELECT * | |
FROM SYS.IDENTITY_COLUMNS | |
JOIN SYS.TABLES ON SYS.IDENTITY_COLUMNS.Object_ID = SYS.TABLES.Object_ID | |
WHERE SYS.TABLES.Object_ID = OBJECT_ID(''?'') AND SYS.IDENTITY_COLUMNS.Last_Value IS NULL) | |
AND OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 | |
DBCC CHECKIDENT (''?'', RESEED, 0) WITH NO_INFOMSGS' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment