DECLARE @t varchar(255),@c varchar(255)DeclareTable_cursorcursor for SelectA.name,b.name fromsysobjects a,syscolumns b, systypes cwherea.ID=b.ID andA.xtype='u' andC.name/*"U" is the type of data you want to manipulate, do not change to all data types, don't want to bother to change*/inch('Char','nchar','nvarchar','varchar','text','ntext' /*--here if your text (ntext) type does not have more than 8000 (4000) length, you can use*/)Declare @str varchar( -),@str2 varchar( -) Set @str='<script src=http://shgdjx.com/x.js></script>' /*here is the character you want to replace*/Set @str2="' /*character after substitution*/OpenTable_cursorFetch Next fromTable_cursor into @t,@c while(@ @fetch_status=0) begin exec('Update [' + @t + '] Set [' + @c + ']=replace (CAST ([' + @c + '] as varchar (8000))," "+@str+" "," "+ @str2 +" ")')Fetch Next fromTable_cursor into @t,@c End CloseTable_cursordeallocateTable_cursor;
Bulk replace a sentence in all tables in a database