当前位置: 代码迷 >> Sql Server >> 怎样删除库里所有表名以“tmp_”开头的表?解决方法
  详细解决方案

怎样删除库里所有表名以“tmp_”开头的表?解决方法

热度:101   发布时间:2016-04-27 16:40:33.0
怎样删除库里所有表名以“tmp_”开头的表?
一句sql能搞定不?
谢谢

------解决方案--------------------
declare cur cursor
read_only
for select distinct table_name from information_schema.columns where table_name like 'tmp_% '

declare @name varchar(40),@sql varchar(1000)
open cur

fetch next from cur into @name
while (@@fetch_status =0)
begin
set @sql = 'drop table ' + @name
exec (@sql)

fetch next from cur into @name
end

close cur
deallocate cur
go
  相关解决方案