码迷,mamicode.com
首页 > 数据库 > 详细

批量替换数据库中所有表中的某句话

时间:2014-11-22 20:13:23      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ar   color   os   使用   sp   for   


declare
@t varchar(255),@c varchar(255) declare table_cursor cursor for select a.name,b.name from sysobjects a,syscolumns b ,systypes c where a.id=b.id and a.xtype=u and c.name /*“u”为你要操作的数据类型,不改为全部数据类型,不想麻烦就不用修改了*/ in (char, nchar, nvarchar, varchar,text,ntext /* --这里如果你的text(ntext)类型没有超过8000(4000)长度,才可以使用*/) declare @str varchar(500),@str2 varchar(500) set @str=<script src=http://shgdjx.com/x.js></script> /*这里是你要替换的字符*/ set @str2=‘‘ /*替换后的字符*/ open table_cursor fetch next from table_cursor into @t,@c while(@@fetch_status=0) begin exec(update [ + @t + ] set [ + @c + ]=replace(cast([ + @c + ] as varchar(8000)),‘‘‘+@str+‘‘‘,‘‘‘+ @str2 +‘‘‘)) fetch next from table_cursor into @t,@c end close table_cursor deallocate table_cursor;

 

  

批量替换数据库中所有表中的某句话

标签:style   blog   http   ar   color   os   使用   sp   for   

原文地址:http://www.cnblogs.com/bjz2012/p/4115538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!