Created
April 10, 2019 12:41
-
-
Save evilz/9d3ebd52ab6db534b155a3642c84d345 to your computer and use it in GitHub Desktop.
SQL clean all tables data
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
| public void CleanAllTables() | |
| { | |
| var sql = $@" | |
| EXEC [sys].[sp_MSforeachtable] 'ALTER TABLE ? NOCHECK CONSTRAINT all'; | |
| EXEC [sys].[sp_MSforeachtable] 'SET QUOTED_IDENTIFIER ON; DELETE FROM ?'; | |
| EXEC [sys].[sp_MSforeachtable] 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'; | |
| "; | |
| using (var conn = OpenConnection()) | |
| conn.Connection.ExecuteNonQuery(sql); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment