我有一个名为reservation
的表,其中包含列reservationStatus
和place
以及另一个表spot
,其中包含spot_id
和spot_status
。
我在预订表中创建了一个触发器,它应该在reservationStatus设置为0后激活但是它不起作用
DELIMITER $$
CREATE TRIGGER spotCancel
AFTER UPDATE ON reservation
FOR EACH ROW
BEGIN
IF NEW.reservationStatus = 0 AND OLD.place <=> 'AbcMall' THEN
UPDATE spot SET spot_status = 0 WHERE spot_id <=> OLD.spot_id;
END IF;
IF NEW.reservationStatus = 0 AND OLD.place <=> 'XyzGym' THEN
UPDATE spot1 SET spot_status =0 WHERE spot_id <=> OLD.spot_id;
END IF;
END$$
DELIMITER ;
此查询每次都无声地失败,我无法找到错误。我正在使用xampp和mysql innoDB存储引擎。
答案 0 :(得分:1)
您错过了END IF
。
DELIMITER $$
CREATE TRIGGER spotCancel
AFTER UPDATE ON reservation
FOR EACH ROW
BEGIN
IF NEW.reservationStatus = 0 AND OLD.place <=> 'Abc' THEN
UPDATE spot SET spot_status = 0 WHERE spot_id <=> OLD.spot_id;
END IF;
IF NEW.reservationStatus = 0 AND OLD.place <=> 'Def' THEN
UPDATE spot1 SET spot_status =0 WHERE spot_id <=> OLD.spot_id;
END IF;
END$$
DELIMITER ;