我遇到触发器问题..如果新的returnBike不为null,我想将值更改为false。
CREATE TRIGGER returnBikeTrigger
AFTER UPDATE ON Rent
FOR EACH ROW
IF (NEW.returnBike <> null) THEN
UPDATE Bike SET isRented = false
WHERE id = (select Bike from Rent); -- but there is Error (missing semicolon)
END IF;
有什么建议吗?
答案 0 :(得分:0)
DELIMITER $$
CREATE TRIGGER returnBikeTrigger
AFTER UPDATE ON Rent
FOR EACH ROW
BEGIN
IF (NEW.returnBike IS NOT NULL) THEN
UPDATE BikeSET isRented = false
WHERE id = new.Bike;
END IF;
END; $$
DELIMITER ;
所以要删除语法分号的问题,在结束后添加分隔符和$$; 无论如何,谢谢你给我一些建议if if comparison!
答案 1 :(得分:0)
我倾向于这样做:
DELIMITER $$
CREATE TRIGGER returnBikeTrigger
AFTER UPDATE ON Rent
FOR EACH ROW
BEGIN
UPDATE Bike
SET isRented = false
WHERE id = new.Bike AND NEW.returnBike IS NOT NULL;
END; $$
DELIMITER ;