SQL 在其他 table 上没有更多行时删除行
SQL delete rows when no more row on other table
我正在尝试在 phpmyadmin 上创建触发器。
一旦 WAITING_ROOM
.
中不再有行,我想从 table NEXT_GAME
中删除所有行
我尝试了以下解决方案:
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
我做错了什么?
您需要一个特定的分隔符来告诉 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 ;
我正在尝试在 phpmyadmin 上创建触发器。
一旦 WAITING_ROOM
.
NEXT_GAME
中删除所有行
我尝试了以下解决方案:
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
我做错了什么?
您需要一个特定的分隔符来告诉 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 ;