mysql触发器查询语法错误

时间:2011-10-17 01:30:19

标签: mysql sql triggers mysql-error-1064

所以我有以下查询:

CREATE TRIGGER `before_delete`
    BEFORE DELETE ON `abc` FOR EACH ROW
    BEGIN
        DELETE FROM def WHERE OLD.id = objID1 OR OLD.id = objID2;
        DELETE FROM ghi WHERE OLD.id = objID;
    END;

但是mysql抱怨第1行'END'附近有语法错误....

我做错了什么?

1 个答案:

答案 0 :(得分:4)

您需要使用DELIMTIER技巧在过程块中包含多个语句。否则,它无法区分您的过程结束与其中的语句结束之间的区别。在documentation页面上,有一个使用delimiter关键字的示例。

为了省去去那个页面并环顾四周的麻烦,我想这会解决它:

DELIMITER $$
CREATE TRIGGER `before_delete`
BEFORE DELETE ON `abc` FOR EACH ROW
BEGIN
    DELETE FROM def WHERE OLD.id = objID1 OR OLD.id = objID2;
    DELETE FROM ghi WHERE OLD.id = objID;
END $$
DELIMITER ;