-
-
Save Deepankar1993/c1c8f72012ea8f0c54a6384887c57dc8 to your computer and use it in GitHub Desktop.
MSSQL Delete all rows from every table and reseed
This file contains hidden or 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
| --Disable all check constraints on all tables | |
| EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' | |
| GO | |
| --Disable all triggers on all tables | |
| EXEC sp_MSForEachTable 'DISABLE TRIGGER ALL ON ?' | |
| GO | |
| --Delete all data from all tables | |
| EXEC sp_MSForEachTable 'SET QUOTED_IDENTIFIER ON; DELETE FROM ?' | |
| GO | |
| --Enable all constraints on all tables | |
| EXEC sp_MSForEachTable 'ENABLE TRIGGER ALL ON ?' | |
| GO | |
| --Enable all triggers on all tables | |
| EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL' | |
| GO | |
| --Ressed the identity columns seed value | |
| EXEC sp_MSForEachTable 'IF(OBJECTPROPERTY(object_id(''?''), ''TableHasIdentity'') = 1) DBCC CHECKIDENT(''?'', RESEED, 0)' | |
| GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment