满意的工作就是对它感兴趣

希望和大家一起研究,并沉醉其中

博客园 首页 新随笔 联系 订阅 管理

先在系统表中找到要处理的表名或者是存储过程的名字,在用游标对其进行处理
注意  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 

posted on 2011-12-26 13:58  半瓶之迷迷糊糊  阅读(744)  评论(0)    收藏  举报