笔记173 使用游标批量删除Sql Server对象
1 --使用游标批量删除Sql Server对象
2 DECLARE cursorname cursor for select 'drop PROCEDURE '+name from sys.objects where name like 'xx%' and type = 'p' --删除对应的存储过程
3 DECLARE cursorname cursor for select 'drop Trigger'+name from sys.objects where name like 'xx%' and type = 'tr' --删除对应的触发器
4
5 open cursorname
6 declare @curname sysname
7 fetch next from cursorname into @curname
8 while(@@fetch_status=0)
9 begin
10 exec(@curname)
11 fetch next from cursorname into @curname
12 end
13 close cursorname
14 deallocate cursorname