Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an after trigger on the Orders table to deduct the ordered quantity from

ID: 3666044 • Letter: C

Question

Create an after trigger on the Orders table to deduct the ordered quantity from the products quantity. It is done in mysql. I dont know how to code this. Can you please help.

Orders table: orderno, customerid,productid,Quantity

Products table: productid,description,quantity,serialNumber,ordereddate

Create an after trigger on the Orders table to deduct the ordered quantity from the products quantity. It is done in mysql. I dont know how to code this. Can you please help.

Orders table: orderno, customerid,productid,Quantity

Products table: productid,description,quantity,serialNumber,ordereddate

Explanation / Answer

CREATE TRIGGER quantity ON Orders AFTER UPDATE AS IF UPDATE(quantity) BEGIN UPDATE p SET quantity = quantity - i.quantity FROM Products AS p JOIN inserted AS i ON i.productid = p.productid -- use the appropriate column for joining JOIN deleted AS d ON i.orderno = d.orderno; END ;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote