/* @pregBD_Piezas.sql */
SET ECHO ON

CREATE SEQUENCE seq_clvProv MINVALUE 100 START WITH 100;

CREATE OR REPLACE TRIGGER insertaProv
BEFORE INSERT ON Proveedor
FOR EACH ROW
DECLARE clv NUMBER(9);
BEGIN
  SELECT seq_clvProv.NEXTVAL INTO clv FROM DUAL;
  :new.clvProv := clv;
END;
/
SHOW ERRORS TRIGGER insertaProv;

INSERT INTO Proveedor(nombProv) VALUES ('Pepe');

SELECT * FROM Proveedor;

DELETE FROM Proveedor WHERE clvProv > 99;

DROP SEQUENCE seq_clvProv;

DROP TRIGGER insertaProv;
