我必须与下面的行进行表:
-
表
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
表中没有添加任何添加的售价...
尝试使用别名:
UPDATE P
SET P.soldQuantity = P.soldQuantity + inserted.quantity
FROM Product P
inner join inserted
ON P.productId = inserted.productId