sql注入 触发器

来源:百度知道 编辑:UC知道 时间:2024/06/18 07:17:39
4个字段类型都是text

CREATE TRIGGER [yj] ON [db0].[y_j_message]
INSTEAD OF INSERT, UPDATE
AS

declare @b varchar(100) --存储字段2
declare @c varchar(100) --存储字段3
declare @d varchar(100) --存储字段4
declare @f varchar(100) --存储字段6
select @b=yj_title,@c=yj_source,@d=yj_author,@f=yj_remarks from inserted
if(@b like '%script%' or @c like '%script%' or @d like '%script%' or @f like '%script%')

begin
ROLLBACK transaction
end

求求各位大侠帮我看看这样学后,什么也插入不了了

你的这段是的意思是 新插入的记录的这几个yj_title,yj_source,yj_author,yj_remarks字段包含字符串script则滚回事务,不插入?

不能这么用rollback tran
可以换个方式来实现。

CREATE TRIGGER [yj] ON [db0].[y_j_message]
INSTEAD OF INSERT, UPDATE
AS
declare @i int
select @i=count(*) from inserted where (yj_title like '%script%' or yj_source like '%script%' or yj_author like '%script%' or yj_remarks like '%script%')

if @i=0
begin
delete a from y_j_message a
inner join deleted b on..........;
go
inserted into y_j_message(yj_title,yj_source,yj_author,yj_remarks)
select yj_title,yj_source,yj_author,yj_remarks from inserted;
go
else
end

if(@b like '%script%' or @c like '%script%' or @d like '%script%' or @f like '%script%')
你写的这一句表示,未插入前你的表里面是不是不会有'%script%'?如果有呢!
这是怎么也插不进去的.
你写这句首先要保证你的表中保证先没有'%script%'.
if (select count(*) from 表 where @b like &#