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
Post a Comment