当前位置: 代码迷 >> Sql Server >> 怎么删除所有以"usp_"为前缀的存储过程,用SQL语句
  详细解决方案

怎么删除所有以"usp_"为前缀的存储过程,用SQL语句

热度:309   发布时间:2016-04-27 21:56:24.0
如何删除所有以"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 '[email protected])
fetch next from c_1 into @pname
end
close c_1
deallocate c_1
  相关解决方案