Home > Database > Mysql Tutorial > SQL Server批量替换所有表中内容sql语句

SQL Server批量替换所有表中内容sql语句

WBOY
Release: 2016-06-07 17:49:09
Original
1184 people have browsed it

像以前做asp的朋友经常会发现自己的数据库所有的内容给插入了一些代码,如果要一个个表一个个记录去删除,太麻烦了,下面我在在网上找到一个可以批量删除的方法,实际上是批量把那段恶意代码替换,非常快速

代码如下:

 代码如下 复制代码

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 /*“u”为你要操作的数据类型,不改为全部数据类型,不想麻烦就不用修改了*/
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;


在SQL Server的查询分析器执行上面的代码,不需要在查看哪个表,哪个字断被注入了,可以很快删除被注入的字段,非常

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template