收集,整理常用的MySQL,MSSQL,Javascript,php技术资料.

MSSQL批量删除数据库中的表或者存储过程(转)

上一篇 / 下一篇  2008-03-07 09:45:26 / 个人分类:MSSQL

大意如下:
    先在系统表中找到要处理的表名或者是存储过程的名字,在用游标对其进行处理
注意  sysobjects.xtype的值不同 删除命令是不同的如删除存储过程用drop PROCEDURE PROCEDURENAME 删除表用 drop table  tablename  sysobjects.xtype的值表示的意思如下表:
C:检查约束。
D:默认的约束
F:外键约束
L:日志
P:存储过程
PK:主键约束
RF:复制过滤存储过程
S:系统表格
TR:触发器
U:用于表格。
UQ:独特的约束。


批量处理的代码如下:
DECLARE cursorname cursor for select 'drop PROCEDURE  '+name from sysobjects where name like 'xx%' and xtype = 'p'--删除对应的存储过程
DECLARE cursorname cursor for select 'drop table  '+name from sysobjects where name like 'xx%' and xtype = 'u'--删除对应的表

open cursorname
declare @curname sysname
fetch next from cursorname into @curname
while(@@fetch_status=0)
  begin
 exec(@curname)
fetch next from cursorname into @curname
end
close cursorname
deallocate cursorname
 
作者: 鹏万里程

TAG: 批量删除数据库中的表 批量删除存储过程 MSSQL

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar