在OrderDetails表上创建一个名为tr_check_qty的UPDATE触发器,以防止更新 如果数量金额大于库存中的单位数量,则OrderDetails表中的数量 产品表。使用以下查询来测试您的触发器。
UPDATE OrderDetails (The trigger should prevent the update.)
SET Quantity = 5
WHERE OrderID = 10008
AND ProductID = 21
UPDATE OrderDetails (The trigger should allow the update.)
SET Quantity = 10
WHERE OrderID = 10008
AND ProductID = 14
我对触发器不太熟悉,但我已经按照以下方式启动了我的代码......
CREATE TRIGGER tr_check_qty
ON OrdersDetails
AFTER UPDATE
AS
IF ( SELECT
od.Quantity
,p.UnitsInStock
FROM
OrderDetails od
INNER JOIN Products p
ON p.ProductID = od.ProductID
WHERE
od.Quantity . p.UnitsInStock
)
BEGIN
RAISERROR ('The Quantity Amount is greater than the units in the Product available!', 16, 1)
ROLLBACK TRANSACTION
RETURN
END
所以我得到了我的错误,但我无法进行此验证。谢谢你的帮助。