I have two tables:
Sales_Order
Order_ID Buyer_ID Emp_ID Status (ENUM)
1 2 3 P
Sales_Order_Details
Detail_ID Order_ID Quantity Item_ID Balance
1 1 10 3 10
2 1 20 6 5
I am trying to create a trigger which looks for updates on the Sales_Order_Details Table and sees that if Balance of any Detail_ID changes, it looks for all the Balance with the Same Order_ID, and if all all 0 then change the status of that Order in Sales_Order table to 'C'.
I am new to triggers and have been reading a few things, but i am quite confused in using them.
CREATE TRIGGER flag_order_complete AFTER UPDATE ON Sales_Order_Details
FOR EACH ROW
BEGIN
IF Balance = '0' THEN
UPDATE Sales_Order SET Status 'C' where Order_ID = old.Order_ID
END
Now this probably is horribly wrong. It will be great if anyone could help me through!