程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> Sql 批量替換所有表中內容

Sql 批量替換所有表中內容

編輯:關於SqlServer
代碼如下:

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;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved