微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Sql 批量替换所有表中内容

<div class="codetitle"><a style="CURSOR: pointer" data="71357" class="copybut" id="copybut71357" onclick="doCopy('code71357')"> 代码如下:

<div class="codebody" id="code71357">
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='' /这里是你要替换的字符/
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;

原文地址:https://www.jb51.cc/mssql/64346.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐