这里的表设计的cartitems表使用WHERE在对重复密钥更新列第
cartitems
cartitem_id PK AI
customer_id FK
item_id FK UNIQUE
item_quantity INT DEFAULT 1
我需要完成
1)如果存在item_id
什么表增加item_quantity
每次用户点击“加入购物车“按钮为相同item_id
2)如果item_id
尚不存在,则运行insert语句。
所以我做了这个。
CREATE DEFINER=`root`@`localhost` PROCEDURE `addItemToCart`(aCustomerId int, aProductId int)
BEGIN
INSERT INTO cart_items(customer_id,product_id)
VALUES(aCustomerId,aProductId)
ON DUPLICATE KEY UPDATE
item_quantity = item_quantity + 1
WHERE customer_id = aCustomerId AND item_id = aProductId;
END
但是,当我检查了,我得到一个错误,指出,在missing semicolon
item_quantity = item_quantity + 1
我无法弄清楚是什么导致了错误。我不知道WHERE
条款是否有问题。
我很感激任何帮助。
谢谢。