触发器有问题

时间:2018-02-27 14:39:46

标签: sql-server triggers

我必须在下面列一行:

  • OrderDetailidorderproductIdquantitypricetotal

  • ProductproductIdproductname,...,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中......

1 个答案:

答案 0 :(得分:0)

尝试使用别名:

UPDATE P
SET P.soldQuantity = P.soldQuantity + inserted.quantity
FROM Product P 
inner join inserted
   ON P.productId  = inserted.productId