具有相同动作时间和事件的多个触发器,用于一个表mysql错误

时间:2013-06-25 23:38:23

标签: mysql triggers

我是触发器的新手,并且正在获得“具有相同操作时间和一个表事件的多个触发器”错误。

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

这是我的问题:

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;

由于我是所有这些的新手,我可能会遗漏一些简单的事情。

1 个答案:

答案 0 :(得分:4)

Brian,可能你已经在桌面上添加并删除了相同的触发器几次,并且在最后再次创建它之前忘记删除它。确保在使用

重新创建之前删除它
DROP TRIGGER [IF EXISTS] [schema_name.]trigger_name

然后

CREATE TRIGGER ....

文档here