Posted by: jwalin on: March 3, 2009
If you want to delete all the records from the all the tables in database you might consider Delete Or Trancate command as both delete all the records from the tables. However it depends on ‘Constraint’ and delete records from one table at a time. But here is the code which delete the records from all the tables in one single shot…
PROCEDURE sp_DeleteAllData
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 ?’
Thank you Susan Sales Harkins who exploer this store procedure
Happy Programming !!!!!