我有两个表正在出售的产品。一个是实际产品的表格,另一个是订购商品的表格。试图创建一个触发器,从另一个表更新一个表的数量
订购商品表记录itemId和销售数量。
我想创建一个触发器,它从订购商品表中获取数据,并更新该商品表的数量,该商品表的数量称为quantityInStock。
这是我写的触发器,但我不断收到一个错误:
delimiter $$
create trigger stockUpdate
after insert on orderItem
for each row
begin
update item(quantityInStock)
set quantityInStock = quantityInStock - orderItem.quantity
where itemId = orderItem.itemId;
end$$
我的错误信息:
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 '(quantityInStock) set quantityInStock = quantityInStock - orderItem.quantity w' at line 5
@Quanlong谢谢。仍然在学习如何正确使用它。 –