Skip to content

Instantly share code, notes, and snippets.

@ZackStone
Created June 22, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZackStone/dcb8c5fd01df4bc23f2a4ecc1d09f2c3 to your computer and use it in GitHub Desktop.
Save ZackStone/dcb8c5fd01df4bc23f2a4ecc1d09f2c3 to your computer and use it in GitHub Desktop.
Drop all tables in a SQL Server database
-- https://stackoverflow.com/questions/8439650/how-to-drop-all-tables-in-a-sql-server-database/20994549#20994549
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'
EXEC sp_msforeachtable 'DROP TABLE ?'
-- but second line you might need to execute more then once until you stop getting error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment