CREATE GENERATOR GEN_EVENT_BRUTTO_PULT_ID;

CREATE TABLE EVENT_BRUTTO_PULT (
    ID           INTEGER NOT NULL,
    PROGRAM_ID   INTEGER NOT NULL,
    DT_EVENT     TIMESTAMP NOT NULL,
    BRUTTO_REAL  FLOAT NOT NULL,
    PULT         FLOAT NOT NULL,
    BRUTTO_PULT  FLOAT NOT NULL
);

ALTER TABLE EVENT_BRUTTO_PULT ADD CONSTRAINT PK_EVENT_BRUTTO_PULT PRIMARY KEY (ID);
ALTER TABLE EVENT_BRUTTO_PULT ADD CONSTRAINT FK_EVENT_BRUTTO_PULT_1 FOREIGN KEY (PROGRAM_ID) REFERENCES PROGRAM (ID) ON DELETE CASCADE;

CREATE OR ALTER TRIGGER EVENT_BRUTTO_PULT_BI FOR EVENT_BRUTTO_PULT
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL)
  THEN
    NEW.ID = GEN_ID(GEN_EVENT_BRUTTO_PULT_ID,1);
END;

CREATE TABLE BRUTTO_PULT_FOTO (
    EVENT_BRUTTO_PULT_ID  INTEGER NOT NULL,
    DT_FOTO               TIMESTAMP NOT NULL
);

ALTER TABLE BRUTTO_PULT_FOTO ADD CONSTRAINT FK_BRUTTO_PULT_FOTO_1 FOREIGN KEY (EVENT_BRUTTO_PULT_ID) REFERENCES EVENT_BRUTTO_PULT (ID) ON DELETE CASCADE;
