首页 > 开发 > 综合 > 正文

数据库所有表替换所有列的特定字符串

2024-07-21 02:49:49
字体:
来源:转载
供稿:网友
数据库所有表替换所有列的特定字符串
DECLARE @TableName VARCHAR(119)DECLARE @TableID INTDECLARE @ColName VARCHAR(111)DECLARE Table_Cursor CURSOR FOR SELECT [name],id FROM sysobjects WHERE xtype='U';OPEN Table_Cursor;FETCH NEXT FROM Table_Cursor INTO @TableName,@TableID;WHILE(@@FETCH_STATUS=0)BEGIN        DECLARE Columns_Cursor CURSOR FOR select [name] from [syscolumns] where [id] = @TableID        OPEN Columns_Cursor;        FETCH NEXT FROM Columns_Cursor INTO @ColName;        WHILE(@@FETCH_STATUS=0)        BEGIN            EXEC('UPDATE '+@TableName+' SET '+@ColName+'=replace('+@ColName+',''lijinsm.cn'',''sdgow.cn'')');            EXEC('UPDATE '+@TableName+' SET '+@ColName+'=replace('+@ColName+',''400-111-1111'',''400-888-8888'')');                                FETCH NEXT FROM   Columns_Cursor INTO @ColName;        END        CLOSE Columns_Cursor;        DEALLOCATE Columns_Cursor;FETCH NEXT FROM   Table_Cursor INTO @TableName,@TableID;ENDCLOSE Table_Cursor;DEALLOCATE Table_Cursor;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表