日期:2014-05-17 浏览次数:20544 次
declare
@objectName as sysname,
@definition as nvarchar(max),
@sourceStr as nvarchar(100),
@replaceStr as nvarchar(100)
set @sourceStr='testString1';--要被替换的字符串,换成你自己的。
set @replaceStr='testString2';--替换字符串,换成你自己的。
select OBJECT_NAME(object_id) as objName,definition
into #tempObj
from sys.sql_modules;
declare cReplacedObj cursor fast_forward for
select objName,definition
from #tempObj;
open cReplacedObj
fetch next from cReplacedObj into @objectName,@definition;
while @@FETCH_STATUS=0
begin
set @definition=replace(@definition,@sourceStr,@replaceStr);--替换操作。
set @definition=N'alter'+substring(@definition,CHARINDEX(' ',@definition),len(@definition));--动态生成alter语句,重新定义相关的函数,存贮过程或触发器。
exec(@definition);--执行alter语句。
fetch next from cReplacedObj into @objectName,@definition;
end
close cReplacedObj;
deallocate cReplacedObj;