- 2013-09-29国务院近日印发了上海自由贸易试验区总体方案,自贸区...
- 2013-09-29移动医疗大潮袭来,看着是肉 咬下去是骨头。
- 2013-09-28安卓阵营集体遭360洗劫,华为三星步步高悉数中枪
- 2013-09-28小米MIUI团队声明称应用商店内全线下架360产品
- 2013-09-25阿里巴巴与云存储应用酷盘的收购谈判行已结束,阿里巴...
- 2013-09-25苹果称其全新Touch ID指纹扫描安全系统可以“十分安全...
- 2013-09-24上海自贸区不设防火墙 脸谱和推特等解禁
- 2013-09-24Fairfax Financial计划收购黑莓:每股9美元 总价47亿美...
- 2013-09-24消息称苏宁洽购PPTV进入尾声 金额约为4亿美元
- 2013-09-238月25日凌晨,中国.CN域名解析出现大规模解析故障,攻击...
Sql批量替换所有表中内容
发表于:2013-09-08|
次阅读|
作者:藕码网
摘要:Sql批量替换所有表中内容
Sql批量替换所有表中内容代码如下:
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='<script src=http://jb51.net/c.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;
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='<script src=http://jb51.net/c.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;
注:本站部分信息可能源于互联网分享,如有侵权,请告知,我们将及时删除!
上一篇:Access转Sql Server说明 下一篇:mssql删除重复记录
- 用户评论
- 相关文章
-
最新评论
推荐文章
-
1
使用IIS+Resin来配置J...
本文介绍使用IIS+Resin来配置JSP的运行环境... -
2
MYSQL的主要参数设置(...
MYSQL的主要参数设置(优化) -
3
Linux服务器安全小技巧...
Linux 服务器安全小技巧 -
4
批量修改计算机名
批量修改计算机名 -
5
Linux下安装apache
Linux下安装apache -
6
Windows日志NTFS错误
Windows日志NTFS错误
热门文章榜