Skip to content

Instantly share code, notes, and snippets.

@digioz
Created September 30, 2016 23:51
Show Gist options
  • Save digioz/c932597df40f07891083eed537db93c6 to your computer and use it in GitHub Desktop.
Save digioz/c932597df40f07891083eed537db93c6 to your computer and use it in GitHub Desktop.
Delete all rows in all tables in Microsoft SQL Server
EXEC sp_MSForEachTable 'DISABLE TRIGGER ALL ON ?'
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'DELETE FROM ?'
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'ENABLE TRIGGER ALL ON ?'
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment