I have 3 tables (Inventory, OrderMaster, OrderDetail). In the table Inventory I have ID_PRODUCT and quantity_inventory columns. In the table OrderMaster I have ID_ORDER and ID_STATE_OF_ORDER (all rows are 3 at the start). Last, but not least, inthe table OrderDetail I have ID_ORDER, ID_PRODUCT and quantity_ordered.
I need a trigger that when the ID_STATE_OF_ORDER in OrderMaster changes to 1, then quanity_inventory in the table Inventory will be the current amount minus quantity_ordered
The current trigger I have is
create or replace trigger Inventory_switch
AFTER UPDATE on OrderMaster
Begin
UPDATE Inventory
SET quantity_inventory =
(SELECT Inventory.quantity_inventory - OrderDetail.quantity_ordered
FROM Inventory, OrderDetail, OrderMaster
WHERE Inventory.ID_PRODUCT = OrderDetail.ID_PRODUCT AND
OrderMaster.ID_ORDER = OrderDetail.ID_ORDER AND
OrderMaster.ID_STATE_OF_ORDER = 1);
End;
This code updates all the rows in Inventory regardless of the conditions I've entered.
Please, I would apreciate any help. Thanks in advance.