Skip to content

Commit

Permalink
Files uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
adityashah95 committed Aug 7, 2019
1 parent 2605664 commit e8fe980
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Lesson08/Exercise32/Trigger.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DROP FUNCTION update_stock;
CREATE FUNCTION update_stock() RETURNS TRIGGER AS $stock_trigger$
DECLARE
stock_qty integer;
BEGIN
stock_qty := get_stock(NEW.product_code) - NEW.qty;
UPDATE products SET stock = stock_qty WHERE product_code=NEW.product_code;
RETURN NEW;
END; $stock_trigger$
LANGUAGE PLPGSQL;

CREATE TRIGGER update_trigger
AFTER INSERT ON order_info
FOR EACH ROW
EXECUTE PROCEDURE update_stock();

0 comments on commit e8fe980

Please sign in to comment.