Skip to content

Instantly share code, notes, and snippets.

@evilz
Created April 10, 2019 12:41
Show Gist options
  • Select an option

  • Save evilz/9d3ebd52ab6db534b155a3642c84d345 to your computer and use it in GitHub Desktop.

Select an option

Save evilz/9d3ebd52ab6db534b155a3642c84d345 to your computer and use it in GitHub Desktop.
SQL clean all tables data
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