在mysql中触发问题

时间:2014-07-30 07:50:41

标签: mysql sql

我有一个名为reservation的表,其中包含列reservationStatusplace以及另一个表spot,其中包含spot_idspot_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存储引擎。

1 个答案:

答案 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 ;