Quick Script to Delete all Table records in MS SQL Server DB

Softex Team will provide here insights, useful tools , tips and tricks about common software systems. We can even put some additional free software utilities for everybody to use . If you have a question about anything related to computers , just ask and we will be happy to answer :)
Site Admin
Posts: 191
Joined: 27 Feb 2012, 16:26
Location: Egypt , Cairo

Quick Script to Delete all Table records in MS SQL Server DB

Postby Softex » 12 Jul 2014, 23:46

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
DeleteAll Records Script - MS SQL 2008 R2.docx
(19.27 KiB) Downloaded 1124 times

Enjoy :)
Softex Software House
Tech. Team

Return to General Tech. Talks

Who is online

Users browsing this forum: No registered users and 1 guest