trigger.sql 496 Bytes
Newer Older
Joel Florentin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
create table registro_inventory(
	film_id integer,
	store_id integer,
	FOREIGN KEY (film_id)
      REFERENCES film (film_id),
	FOREIGN KEY (store_id)
      REFERENCES store (store_id)
);

CREATE OR REPLACE FUNCTION inventory_update()
  RETURNS TRIGGER 
  LANGUAGE PLPGSQL
  AS
$$
BEGIN
	
	 INSERT INTO registro_inventory(film_id,store_id)
	VALUES(OLD.film_id,OLD.store_id);
END;
$$

CREATE TRIGGER inventory_log
  AFTER UPDATE
  ON inventory
  FOR EACH ROW
  EXECUTE PROCEDURE inventory_update();