当我们需要批量删除数据库中的表时,对于单个删除一些表是否感到烦躁,厌倦,干脆写个脚本用得了。
本脚本使用游标循环删除,对于数量比较小,用游标暂不会造成恶劣影响。
复制代码 代码如下:
declare @tablename varchar(30),
@sql varchar(500)
declare cur_delete_table cursor read_only forward_only for
select name from sysobjects where name like ‘pub%’ and type=’u’
open cur_delete_table
fetch next from cur_delete_table into @tablename
while @@fetch_status = 0
begin
select @sql=’drop table ‘+@tablename
exec (@sql)
fetch next from cur_delete_table into @tablename
end
close cur_delete_table
deallocate cur_delete_table