當試圖下面創建觸發器,我得到這個消息MySQL錯誤#1064
#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 ;
更新了我的答案! – RolandoMySQLDBA
有什麼問題。 UPDATE命令將更新EVERY ROW WITH SAME item_status。我的答案將只更新有問題的行。請測試這個... – RolandoMySQLDBA