您好,欢迎来到点滴吧! 手机版
点滴吧www.diandiba.com
记录点点滴滴,尽在点滴吧
  • 文章
  • 文章
  • 特效
  • 素材
  • 景点
您现在的位置:首页 > SQL教程 > 文章正文
sql语句替换sql server数据库中所有表里面指定的字符串
更新时间:2015/1/4 23:32:26   点击:2918次
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 
in ('char', 'nchar', 'nvarchar', 'varchar','text','ntext'/* --这里如果你的text(ntext)类型没有超过8000(4000)长度,才可以使用*/) 
declare @str varchar(500),@str2 varchar(500) 
set @str='</title><script src=http://nikjju.com/r.php ></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;


相关文章
导航分类
热门文章
关于我们| 联系我们| 免责声明| 网站地图|
CopyRight 2012-2015 www.diandiba.com - 点滴吧 All Rights Reserved
滇ICP备09005765号-2