How to delete all rows from all tables in a SQL Server database?

Note that TRUNCATE won’t work if you have any referential integrity set. In that case, this will work: EXEC sp_MSForEachTable ‘DISABLE TRIGGER ALL ON ?’ GO EXEC sp_MSForEachTable ‘ALTER TABLE ? NOCHECK CONSTRAINT ALL’ GO EXEC sp_MSForEachTable ‘SET QUOTED_IDENTIFIER ON; DELETE FROM ?’ GO EXEC sp_MSForEachTable ‘ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL’ GO … Read more

tech