Mahmoud ElMansy: knowledge meant to be free

Delete All Data From Your DataBase SQL

Here is a simple and efficient code to empty DataBase from data,
using one of the non documented SQL functions “sp_MSFOREACHTABLE”.

Using This code

CREATE PROCEDURE dbo.[sp_DeleteAllData]
AS
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'ALTER TABLE ? DISABLE TRIGGER ALL'
EXEC sp_MSForEachTable 'DELETE FROM ?'
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'ALTER TABLE ? ENABLE TRIGGER ALL'
EXEC sp_MSFOREACHTABLE 'SELECT * FROM ?'
GO

By calling this Procedure you will get clean DataBase.
you could change the code to make “truncate” instade of delete.