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
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
网友评论