/******************************************************************************/
/****                                Tables                                ****/
/******************************************************************************/


CREATE GENERATOR GTBCATALOGO_VINCULO_IMG;

CREATE TABLE TBCATALOGO_VINCULO_IMG (
    ID           INTEGER NOT NULL,
    MODELO_ID    INTEGER NOT NULL,
    QTD_IMAGENS  INTEGER
);




/******************************************************************************/
/****                             Primary keys                             ****/
/******************************************************************************/

ALTER TABLE TBCATALOGO_VINCULO_IMG ADD CONSTRAINT PK_TBCATALOGO_VINCULO_IMG PRIMARY KEY (ID, MODELO_ID);


/******************************************************************************/
/****                               Indices                                ****/
/******************************************************************************/

CREATE INDEX ITBCATALOGO_VINCULO_IMG_01 ON TBCATALOGO_VINCULO_IMG (ID);
CREATE INDEX ITBCATALOGO_VINCULO_IMG_02 ON TBCATALOGO_VINCULO_IMG (MODELO_ID);


/******************************************************************************/
/****                               Triggers                               ****/
/******************************************************************************/



SET TERM ^ ;



/******************************************************************************/
/****                         Triggers for tables                          ****/
/******************************************************************************/



/* Trigger: TTBCATALOGO_VINCULO_IMG_B01I */
CREATE OR ALTER TRIGGER TTBCATALOGO_VINCULO_IMG_B01I FOR TBCATALOGO_VINCULO_IMG
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
    IF (COALESCE(NEW.ID, 0) = 0) THEN
        NEW.ID = GEN_ID(GTBCATALOGO_VINCULO_IMG, 1);
END
^

SET TERM ; ^