SQLServer用t-sql命令批量删除数据库中指定表(游标循环删除)
当我们需要批量删除数据库中的表时,对于单个删除一些表是否感到烦躁,厌倦,干脆写个脚本用得了。
本脚本使用游标循环删除,对于数量比较小,用游标暂不会造成恶劣影响。
代码如下:
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
相关推荐
zycchun 2020-10-16
liuyang000 2020-09-25
talkingDB 2020-06-12
LuoXinLoves 2020-06-06
Justdoit00 2020-04-26
lt云飞扬gt 2020-04-25
流云追风 2020-04-22
lt云飞扬gt 2020-04-21
yuanshuai 2020-03-06
dreamhua 2020-02-21
ALiDan 2020-02-18
dreamhua 2020-01-31
whyname 2019-12-29
tanrong 2019-12-17
暗夜之城 2019-11-13
liuyang000 2019-11-01
dreamhua 2019-10-28
廖金龙 2016-01-04