日期:2014-05-19  浏览次数:20741 次

如何删除所有以"usp_"为前缀的存储过程,用SQL语句
我想删除所有以   USP_   这个前缀开头的存储过程   怎么写啊   DROP   PROCEDURE   'usp_% '   这样写语法错误   怎么写才对    


------解决方案--------------------
将所有USP_开头的存储过程名线选出来,放入游标。
declare c_1 cursor for select name from sysobjects where name like 'USP_% ' and xtype= 'P '
遍历游标,创建动态SQL语句,删除存储过程
declare @pname nvarchar(100)
open c_1
fetch next from c_1 into @pname
while @@fetch_status=0
begin
exec ( 'drop PROCEDURE '+@pname)
fetch next from c_1 into @pname
end
close c_1
deallocate c_1