triger.sql 542 Bytes
Newer Older
willgonzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18


CREATE TABLE REGISTRO_INVENTORY(
	REGISTRO_ID INTEGER PRIMERY KEY,
	FECHA DATE,
	FILM_ID INTEGER NOT NULL,
	STORE_ID INTEGER NOT NULL,
	CONSTRAINT FK_FILM_ID FOREIGN KEY(FILM_ID) REFERENCES FILM(FILM_ID), 
	CONSTRAINT FK_STORE_ID FOREIGN KEY(STORE_ID) REFERENCES STORE(STORE_ID) 
);

CREATE OR REPLACE TRIGGER INSERTAR_INVENTORY 
	AFTER UPDATE ON INVENTORY
	FOR EACH ROW
	BEGIN
		 INSERT INTO  REGISTRO_INVENTORY (REGISTRO_ID, FECHA, FILM_ID, STORE_ID) VALUES (DEFAULT, OLD.LAST_UPDATE, OLD.FILM_ID, old.STORE_ID);
END INSERTAR_INVENTORY;
/