Skip to content

Instantly share code, notes, and snippets.

@jeremybeavon
Created March 10, 2015 22:41
Show Gist options
  • Save jeremybeavon/e319f463f05b898571ea to your computer and use it in GitHub Desktop.
Save jeremybeavon/e319f463f05b898571ea to your computer and use it in GitHub Desktop.
Delete all data from database
-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'DELETE FROM ?'
GO
-- enable referential integrity again
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment