我在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条答案
按热度按时间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 ;