我正在尝试在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
我做错了什么?
答案 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 ;