Forked from jasongaylord/delete_tables_byprefix.sql
Created
November 18, 2012 11:05
-
-
Save mahizsas/4104581 to your computer and use it in GitHub Desktop.
TSQL - Delete Tables with a Prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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