假设我有一张表叫test,里面有三个字段。分别是id name news
然后我写一个触发器。drop trigger if exists tdu;
create trigger tdu after INSERT
on test for each row
begin
if new.news is NULL then
update test
set test.news=new.name
where test.id=new.id;
end if;
end然后执行 INSERT into test(id,name)value('1','ddd')然后就出现了错误 如下:
[Err] 1442 - Can't update table 'test' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
然后我写一个触发器。drop trigger if exists tdu;
create trigger tdu after INSERT
on test for each row
begin
if new.news is NULL then
update test
set test.news=new.name
where test.id=new.id;
end if;
end然后执行 INSERT into test(id,name)value('1','ddd')然后就出现了错误 如下:
[Err] 1442 - Can't update table 'test' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
create trigger tdu after INSERT
on test for each row
begin
if new.news is NULL then
SET new.news=new.name;
end if;
end
大哥,还是不行啊,我重新修改触发器出现
[Err] 1362 - Updating of NEW row is not allowed in after trigger
能在帮我看看吗?
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'end
end' at line 6能继续帮我看看么.打扰你了。。
create trigger tdu BEFORE INSERT
on test for each row
begin
if new.news is NULL then
SET new.news=new.name
end if;
end
CREATE TRIGGER tdu BEFORE INSERT
ON test FOR EACH ROW
BEGIN
IF NEW.news IS NULL THEN
SET NEW.news=NEW.`name`;
END IF;
END$$
DELIMITER ;