gpt4 book ai didi

mysql - 对于一个表 mysql 错误,具有相同 Action 时间和事件的多个触发器

转载 作者:行者123 更新时间:2023-11-29 01:42:18 25 4
gpt4 key购买 nike

我是触发器的新手,我收到“多个触发器具有相同的 Action 时间和一个表的事件”错误。

我创建了一个 AFTER Update 和一个 AFTER Delete,它们是两个独立的操作时间/事件,所以我不确定为什么会收到错误。

这是我的查询:

CREATE TRIGGER `new_enrolment` AFTER INSERT ON `mdl_user_enrolments` FOR EACH ROW BEGIN
INSERT INTO c_master (
ud,
firstname,
lastname,
email,
username,
cid,
course
)
SELECT
mdl_user.id AS uid,
mdl_user.firstname,
mdl_user.lastname,
mdl_user.email,
mdl_user.suspended,
mdl_user.username,
mdl_enrol.courseid AS cid,
mdl_course.fullname AS course
FROM mdl_user_enrolments INNER JOIN mdl_enrol ON mdl_user_enrolments.enrolid = mdl_enrol.id
INNER JOIN mdl_course ON mdl_enrol.courseid = mdl_course.id
INNER JOIN mdl_user ON mdl_user.id = mdl_user_enrolments.userid
WHERE userid = NEW.userid;
END;

CREATE TRIGGER `remove_enrolment` AFTER DELETE ON `mdl_user_enrolments` FOR EACH ROW BEGIN
SELECT mdl_enrol.courseid,
mdl_user_enrolments.userid,
mdl_user_enrolments.enrolid
FROM mdl_user_enrolments INNER JOIN mdl_enrol ON mdl_user_enrolments.enrolid = mdl_enrol.id
WHERE mdl_user_enrolments.enrolid = OLD.enrolid

DELETE FROM c_master
WHERE uid = OLD.userid AND mdl_enrol.courseid;
END;

由于我是新手,所以我可能遗漏了一些简单的东西。

最佳答案

Brian,您可能已经在表中多次添加和删除相同的触发器,而您忘记了上次在再次创建之前删除它。确保在使用

再次创建之前已将其删除
DROP TRIGGER [IF EXISTS] [schema_name.]trigger_name

然后

CREATE TRIGGER ....

文档 here .

关于mysql - 对于一个表 mysql 错误,具有相同 Action 时间和事件的多个触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17309322/

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