为什么我的触发器不起作用?错误1064

时间:2018-10-24 18:12:33

标签: mysql triggers mysql-workbench

我在MySql Workbench中出现语法错误,但似乎找不到它... 我的触发器正确吗?

CREATE TRIGGER after_delete_user AFTER UPDATE
ON users FOR EACH ROW
BEGIN
    IF NEW.deletionDate != NULL
        THEN
            DELETE FROM requests WHERE user_id = OLD.user_id;
            DELETE FROM appointments WHERE user_id = OLD.user_id;
    END IF;
END;

谢谢!

1 个答案:

答案 0 :(得分:1)

需要将定界符定义为;以外的其他内容。最后将其重新定义为null。要比较IS NOT NULL的值,我们需要使用DELIMITER $$ CREATE TRIGGER after_delete_user AFTER UPDATE ON users FOR EACH ROW BEGIN IF NEW.deletionDate IS NOT NULL THEN DELETE FROM requests WHERE user_id = OLD.user_id; DELETE FROM appointments WHERE user_id = OLD.user_id; END IF; END$$ DELIMITER ;

"/bin/sleep 3 && /usr/bin/beanstalkd -b /binlog"