Maintain stock on order item insert
SQL
Easy
0 views
Problem Description
When a new OrderItems row is inserted, decrement Inventory.qty.
Output Format
Trigger created
Sample Test Case
Input:
OrderItems, Inventory
Constraints
Check qty >= requested elsewhere
Official Solution
CREATE TRIGGER trg_orderitems_decrement AFTER INSERT ON OrderItems FOR EACH ROW UPDATE Inventory SET qty = qty - NEW.qty WHERE product_id = NEW.product_id;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!