Skip to content

Instantly share code, notes, and snippets.

@shammelburg
Created November 9, 2020 09:05
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 shammelburg/9a68c4dc37fa5cc66e93cbd19ca2e3c2 to your computer and use it in GitHub Desktop.
Save shammelburg/9a68c4dc37fa5cc66e93cbd19ca2e3c2 to your computer and use it in GitHub Desktop.
Truncate all tables in Azure SQL Database
DECLARE @SQL varchar(max)
SET @SQL = (SELECT ' TRUNCATE TABLE [' + TABLE_SCHEMA +'].['+ TABLE_NAME + '];'
FROM INFORMATION_SCHEMA.TABLES
ORDER BY TABLE_SCHEMA DESC
FOR XML PATH(''))
-- Print Statement
-- SELECT @SQL
-- Execute command
-- EXEC (@SQL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment