Thursday, 30 January 2020

How to TRUNCATE ALL TABLES

In this article, I am explaining, How to delete all data or truncate all tables from the database in SQL Server. By using the below queries delete the data, not the structure.

For this, we can use the sp_MSforeachtable stored procedure:

For TRUNCATE  all tables :


USE DatabaseName
EXEC sp_MSforeachtable 'TRUNCATE TABLE ?'

For delete all data from tables :

USE MyDatabaseName

EXEC sp_MSforeachtable 'DELETE FROM ?'