innhyul

Between tomorrow's dream and yesterday's regret is todays opportunity.

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

大意如下:

    先在系统表中找到要处理的表名或者是存储过程的名字,在用游标对其进行处理

注意  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 2010-04-01 14:55  bufferi  阅读(304)  评论(0编辑  收藏  举报