How to delete and reseed all data in a SQL Server database
May 23, 2012
0 Comments
If you want to delete all data in a SQL Server database and reseed the tables that contain a identity column, you can use the following code:
exec sp_msforeachtable "alter table ? nocheck constraint all"; exec sp_msforeachtable "delete from ?"; exec sp_msforeachtable "if exists(select 1 from sys.identity_columns where object_name(object_id) = '?') begin dbcc checkident ( '?', reseed, 0) end"; exec sp_msforeachtable "alter table ? with check check constraint all";Tags: SQL Server