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 ;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.