我在触发器中遇到此错误,这是为了防止库存量少于订购数量的产品的订单更新。这是我的触发器:
alter trigger tr_check_qty
on OrderDetails
for update
as
if (select Quantity from inserted i) > (select UnitsInStock from Products p
inner join inserted i on p.ProductID = i.ProductID)
begin
print 'Ordered amount cannot be greater than units in stock'
rollback transaction
end
这是我执行触发器的方式:
UPDATE OrderDetails
SET Quantity = 40
WHERE OrderID = 10044 AND ProductID = 77