gpt4 book ai didi

MySQL 触发器和错误代码 1362

转载 作者:行者123 更新时间:2023-11-29 22:35:55 25 4
gpt4 key购买 nike

所以我有以下触发器查询:

DELIMITER $$
CREATE TRIGGER user_log_update BEFORE UPDATE on user_log
FOR EACH ROW
BEGIN
insert into user_log
(id, user_id, name, username, password, email, user_type_id, created)
VALUES(OLD.id, OLD.user_id, OLD.name, OLD.username, OLD.password, OLD.email, OLD.user_type_id, OLD.created);
IF (OLD.id = 1) THEN
SET OLD.id = OLD.id +1;
END IF;
SELECT * FROM user_log;
END$$
DELIMITER ;

当我尝试执行脚本的这一部分时,我收到错误代码:1362。触发器中不允许更新旧行

我不知道为什么会出现此错误,而且我没有发现语法有任何问题。

有谁知道怎么解决吗?

最佳答案

因此,增加 new 来代替:

DELIMITER $$
CREATE TRIGGER user_log_update BEFORE UPDATE on user_log
FOR EACH ROW
BEGIN
insert into user_log(id, user_id, name, username, password, email, user_type_id, created)
VALUES(OLD.id, OLD.user_id, OLD.name, OLD.username, OLD.password, OLD.email, OLD.user_type_id, OLD.created);
IF (OLD.id = 1) THEN
SET NEW.id = OLD.id +1;
END IF;
END$$
DELIMITER ;

关于MySQL 触发器和错误代码 1362,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29552464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com