Delete/Drop similar tables in SQL Server -


i have database in sql server there many similar tables such dbo.dos_150602_xyz. tried delete tables 1506 in them typing:

drop table dbo.dos_1506*;  

but didn't work. how else can perform this?

thanks.

just make things bit easier op.

sample table creation script: create table table_pattern_name_1 ( s1 varchar(20), n1 int ); create table table_pattern_name_2 ( s1 varchar(20), n1 int ); create table table_pattern_name_3 ( s1 varchar(20), n1 int ); create table table_pattern_name_4 ( s1 varchar(20), n1 int );

table drop script: declare @cmd varchar(4000) declare cmds cursor select 'drop table [' + table_name + ']' information_schema.tables table_name 'table_pattern_name_%' open cmds while 1=1 begin fetch cmds @cmd if @@fetch_status != 0 break print @cmd exec(@cmd) end close cmds; deallocate cmds

ssms output: drop table [table_pattern_name_1] drop table [table_pattern_name_2] drop table [table_pattern_name_3] drop table [table_pattern_name_4]

let me know if works example.

thanks, matt jones microsoft sql server


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -