Sql 批量替换所有表中内容

发布时间:2022-04-18 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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;

脚本宝典总结

以上是脚本宝典为你收集整理的Sql 批量替换所有表中内容全部内容,希望文章能够帮你解决Sql 批量替换所有表中内容所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: