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

daupos2t  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(303)

我在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;

谢谢!

tyu7yeag

tyu7yeag1#

需要将分隔符定义为除 ; . 重新定义为 ; 最后。比较 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 ;

相关问题