您好我的触发器有问题:
CREATE TRIGGER sprLog AFTER UPDATE ON Users FOR WACH ROW
BEGIN
IF OLD.wl < NEW.wl THEN
IF NEW.wl = 3 THEN
INSERT INTO blocked(uid, time) VALUE(NEW.ID, 15);
UPDATE Users SET state=3 WHERE ID=NEW.ID;
END IF;
END IF;
END;
现在,当我尝试执行此查询时:UPDATE Users SET wl=3 WHERE ID=1
我有错误:
#1442 - Can't update table 'Users' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
我希望您从触发器中了解我想要做什么。我知道这个触发器会导致自己,但我不知道如何以其他方式做到这一点。我尝试使用两个触发器,一个用户更新后,第二个插入后阻止,但问题是相同的。
答案 0 :(得分:1)
如果要修改正在更新的行,请创建before update
触发器。
CREATE TRIGGER sprLog BEFORE UPDATE ON Users FOR WACH ROW
BEGIN
IF OLD.wl < NEW.wl THEN
IF NEW.wl = 3 THEN
INSERT INTO blocked(uid, time) VALUE(NEW.ID, 15);
SET NEW.state = 3;
END IF;
END IF;
END;