尝试在下面创建触发器时,我收到此消息
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; END' at line 9
有人可以帮忙吗?谢谢
delimiter $$
CREATE TRIGGER tr_update_item_status
AFTER UPDATE ON check_in
FOR EACH ROW
BEGIN
IF OLD.quantity > 0 AND NEW.quantity <= 0 THEN
UPDATE check_in SET item_status = 'Sold';
ELSEIF OLD.quantity <= 0 AND NEW.quantity > 0 THEN
UPDATE check_in SET item_status = 'Available';
ENDIF;
END;$$
delimiter ;
答案 0 :(得分:3)
DELIMITER $$
CREATE TRIGGER tr_update_item_status
AFTER UPDATE ON check_in
FOR EACH ROW
BEGIN
IF OLD.quantity > 0 AND NEW.quantity <= 0 THEN
UPDATE check_in SET item_status = 'Sold';
ELSEIF OLD.quantity <= 0 AND NEW.quantity > 0 THEN
UPDATE check_in SET item_status = 'Available';
END IF;
END $$
DELIMITER ;
这应该有效。一切顺利。
答案 1 :(得分:1)
DELIMITER $$
CREATE TRIGGER tr_update_item_status
BEFORE UPDATE ON check_in
FOR EACH ROW
BEGIN
IF OLD.quantity > 0 AND NEW.quantity <= 0 THEN
SET NEW.item_status = 'Sold';
ELSEIF OLD.quantity <= 0 AND NEW.quantity > 0 THEN
SET NEW.item_status = 'Available';
END IF;
END; $$
DELIMITER ;
三(3)件事: