Quick Script to Delete all Table records in MS SQL Server DB
1 post
• Page 1 of 1
Quick Script to Delete all Table records in MS SQL Server DB
Since our line of business involves administration of literally hundreds of Microsoft SQL Server Databases, We had always have the need for a quick script to clean some database tables from all records without the need of writing custom script with "delete * from each table name" , we just needed a script that loops on all tables, just delete all records and then reset the identity columns.
Out technical team have found such script and we would love to share it with the world
this works with SQL Server 2008 Databases or later, and if any table in the database does not have identity column inside it, the script will raise the error but the records will be deleted anyway, so do not worry about it.
It is very important to backup your database before using such scripts because there is no going back once you run it
Script below in the attached file
Enjoy
Out technical team have found such script and we would love to share it with the world

this works with SQL Server 2008 Databases or later, and if any table in the database does not have identity column inside it, the script will raise the error but the records will be deleted anyway, so do not worry about it.
It is very important to backup your database before using such scripts because there is no going back once you run it
Script below in the attached file
Enjoy

1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest