当其他表上没有更多行时,SQL删除行

时间:2019-03-19 15:27:51

标签: mysql phpmyadmin database-trigger

我正在尝试在phpmyadmin上创建触发器。 我想在NEXT_GAME中没有更多行时立即删除表WAITING_ROOM中的所有行。

我尝试了以下解决方案:

CREATE TRIGGER delete_begin_date AFTER DELETE
ON NEXT_GAME FOR EACH ROW
BEGIN
    IF NOT EXISTS (SELECT * FROM WAITING_ROOM) THEN
        DELETE FROM NEXT_GAME;
    END IF;
END

我遇到以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 5

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您需要一个特定的定界符来告诉MySQL下一个;并没有结束CREATE TRIGGER语句。

DELIMITER $$
CREATE TRIGGER delete_begin_date AFTER DELETE
ON NEXT_GAME FOR EACH ROW
BEGIN
    IF NOT EXISTS (SELECT * FROM WAITING_ROOM) THEN
        DELETE FROM NEXT_GAME;
    END IF;
-- vv----------------------- Notice this
END$$
DELIMITER ; -- switch back to the regular ;