Handle update of qty in order items
SQL
Hard
0 views
Problem Description
On update of OrderItems.qty, adjust Inventory by the difference.
Output Format
Trigger created
Sample Test Case
Input:
OrderItems, Inventory
Constraints
diff = NEW.qty - OLD.qty
Official Solution
CREATE TRIGGER trg_adjust_stock AFTER UPDATE ON OrderItems FOR EACH ROW UPDATE Inventory SET qty = qty - (NEW.qty - OLD.qty) WHERE product_id = NEW.product_id;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!