• 替换SQL Server数据库中所有表的所有字段的某些内容


    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 b.xtype=c.xtype 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;
     
     
    问题:修改的字段类型,一定要包含在上面修改的类型里面,没有的话就加上去
  • 相关阅读:
    迭代器和生成器
    New test
    MySQL笔记整理
    Python基础数据类型
    Python基础
    Python入门知识
    Linux / MacOS 下Redis 安装、配置和连接
    NuGet的使用心得
    简单工厂模式和策略模式的区别与结合
    NuGet的使用和服务搭建
  • 原文地址:https://www.cnblogs.com/zhongzunmu/p/5429982.html
Copyright © 2020-2023  润新知