以下是我在尝试从“收藏夹”中删除记录之前尝试编写的触发器。表,基本上检查是否a)我想删除的景点甚至在数据库中表示,b)如果吸引力甚至被用户所喜爱,则最喜欢的是。问题是,由于某种原因,触发器似乎没有被触发(我试图看看它是否在'插入评论'部分)。有谁看到了原因?
DELIMITER //
CREATE TRIGGER checkFavoritesBeforeDeleting
BEFORE DELETE
ON favorites
FOR EACH ROW
BEGIN
DECLARE attExists INT;
DECLARE attNotFavorited INT;
-- insert into review values (5, 1, 'tester');
SELECT count(*) into attExists from attraction where attraction_id = old.attraction_id;
SELECT count(*) into attNotFavorited from favorites where account_id =
old.account_id and attraction_id = old.attraction_id;
IF attExists = 0 OR attExists IS NULL then
signal sqlstate '45000' set message_text = 'Sorry, but the attraction you wanted to delete does not exist in our database.';
ELSEIF attNotFavorited < 1 then
signal sqlstate '45000' set message_text = 'Sorry, but the favorited attraction you wanted to delete was not even in your list of favorites!';
END IF;
END //
DELIMITER ;