Handle update of qty in order items

Handle update of qty in order items

Hard SQL Triggers 17 views
Explanation Complexity

Problem Statement

On update of OrderItems.qty, adjust Inventory by the difference.

Input Format

SQL DDL

Output Format

Trigger created

Example

OrderItems, Inventory
Trigger created

Constraints

diff = NEW.qty - OLD.qty

Input / Output Format

Input Format
SQL DDL
Output Format
Trigger created
Constraints
diff = NEW.qty - OLD.qty

Examples

Input:
OrderItems, Inventory
Output:
Trigger created

Example Solution (Public)

SQL
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;

Official Solution Code

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;
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.