DROP TABLE informesFallos;

CREATE TABLE informesFallos (
  idInforme NUMBER(5) CONSTRAINT idInforme_PK PRIMARY KEY,
  clvPieza  NUMBER(9),
  clvProv   NUMBER(9),
  fecha     DATE,
  empleado  VARCHAR2(255),
  descr     VARCHAR2(255),
  CONSTRAINT clvProvInforme_FK  FOREIGN KEY (clvProv) REFERENCES Proveedor(clvProv) ON DELETE cascade,
  CONSTRAINT clvPiezaInforme_FK FOREIGN KEY (clvPieza) REFERENCES Pieza(clvPieza) ON DELETE cascade
);

CREATE TABLE sumNoValidos (
  clvPieza NUMBER(9),
  clvProv  NUMBER(9),
  PRIMARY KEY (clvProv, clvPieza),
  FOREIGN KEY (clvProv)  REFERENCES Proveedor(clvProv) ON DELETE cascade,
  FOREIGN KEY (clvPieza) REFERENCES Pieza(clvPieza) ON DELETE cascade
);

CREATE TABLE totalFallos (
  clvPieza  NUMBER(9),
  clvProv   NUMBER(9),
  numFallos NUMBER(3),
  PRIMARY KEY (clvProv, clvPieza),
  FOREIGN KEY (clvProv)  REFERENCES Proveedor(clvProv) ON DELETE cascade,
  FOREIGN KEY (clvPieza) REFERENCES Pieza(clvPieza) ON DELETE cascade
);
