Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mahizsas/4104581 to your computer and use it in GitHub Desktop.
Save mahizsas/4104581 to your computer and use it in GitHub Desktop.
TSQL - Delete Tables with a Prefix
declare @cmd varchar(4000)
declare cmds cursor for
Select 'drop table [' + Table_Name + ']'
From INFORMATION_SCHEMA.TABLES
Where Table_Name like 'prefix%'
open cmds
while 1=1
begin
fetch cmds into @cmd
if @@fetch_status != 0 break
exec(@cmd)
end
close cmds
deallocate cmds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment