Dream Tech Blog

A person with no dream in life can never live a happy life.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

将所有存储过程的某个参数,修改成另一个定义

Posted on 2004-03-24 20:08  Dream  阅读(969)  评论(0编辑  收藏  举报
--* 感謝CSDN的zjcxc(: 邹建 :)
declare @o_para varchar(100),@n_para varchar(100)
select @o_para='@resname varchar(10)' --你的存储过程中,参数原来的定义
 ,@n_para='@resname varchar(100)' --新的参数定义
declare tb cursor for
select name=object_name(id),id,colid
from syscomments 
where objectproperty(id,'IsProcedure')=1 and status=0
 and text like '%'+@o_para+'%'
order by name
declare @s1 varchar(8000),@s2 varchar(8000),@s3 varchar(8000),@s4 varchar(8000)
 ,@name sysname,@id int,@colid int,@oid int
open tb
fetch next from tb into @name,@id,@colid
select @s2='',@s3=''
while @@fetch_status=0
begin
 if @oid<>@id
 begin
  exec(@s1)
  exec(@s2+'
'+@s3+'
'+@s4+')')  
  select @s1='drop proc ['+@name+']'
   ,@s2='declare @'+cast(@colid as varchar)+' varchar(8000)'
   ,@s3='select @'+cast(@colid as varchar)+'=replace(text,'''
    +@o_para+''','''+@n_para+''')
   from syscomments where id='+cast(@id as varchar)
   +' and colid='+cast(@colid as varchar)
   ,@s4='exec(@'+cast(@colid as varchar)
 end
 else
  select @s2=@s2+',@'+cast(@colid as varchar)+' varchar(8000)'
   ,@s3=@s3+'
select @'+cast(@colid as varchar)+'=replace(text,'''
    +@o_para+''',''@resname varchar(200)'')
   from syscomments where id='+cast(@id as varchar)
   +' and colid='+cast(@colid as varchar)
   ,@s4=@s4+'+@'+cast(@colid as varchar)
 set @oid=@id
 fetch next from tb into @name,@id,@colid
end
close tb
deallocate tb