mssql sqlserver 批量删除所有存储过程的方法分享

转自:http://www.maomao365.com/?p=6864

摘要:
下文讲述采用sql脚本批量删除所有存储过程的方法,如下所示:
实验环境:sqlserver 2008 R2



平常使用sql脚本,删除存储过程,我们只可以使用删除命令一条一条的删除存储过程,下文介绍一种简便方法,可以对系统中所有的存储过程进行删除,
<span style="color:red;">
实现思路:
1 采用临时表将存储过程名称缓存
2 通过循环临时表,输出删除存储过程脚本
3 执行脚本

declare @t table(keyId int identity(1,1),tableName varchar(256))
----生成临时表
insert into @t(tableName) 
select [name] from sysobjects where type='P'

declare @i int @iMax int ,@info varchar(256)
set @i =1 
select @imax=max(keyId) from @t as t

while @i <@imax
begin
select @info = t.tableName from @t as t where t.keyId =@i

if @info is not null 
begin
exec ('drop proc '+@info) ---遍历删除存储过程
end 

set @i = @i+1 
set @info =null 
end

 

posted @ 2018-07-14 20:25  Adeal2008  阅读(1230)  评论(0编辑  收藏  举报