我必须在下面列一行:
表OrderDetail
:idorder
,productId
,quantity
,price
,total
表Product
:productId
,productname
,...,soldQuantity
我OrderDetail
表上的触发器:
ALTER trigger [dbo].[Sold]
On [dbo].[OrderDetail]
FOR Insert
AS
UPDATE Product
SET soldQuantity = soldQuantity + inserted.quantity
FROM Product inner join inserted
ON Product.productId = inserted.productId
当我插入OrderDetail
表时,Product
表格中没有任何内容添加到soldQuantity中......
答案 0 :(得分:0)
尝试使用别名:
UPDATE P
SET P.soldQuantity = P.soldQuantity + inserted.quantity
FROM Product P
inner join inserted
ON P.productId = inserted.productId