CREATE SEQUENCE GEN_RESSUPRIMENTO_ID;
CREATE GENERATOR GTBTEMP_ITENS_PED_RESSUPRIMENTO;

CREATE TABLE TBTEMP_ITENS_PED_RESSUPRIMENTO (
    ID                    INTEGER NOT NULL,
    RESSUPRIMENTO_ID      INTEGER NOT NULL,
    ESTABELECIMENTO_ID    INTEGER,
    LOCALIZACAO_ID        INTEGER,
    DATA_INICIO           DATE,
    DATA_FIM              DATE,
    DADOS                 BLOB SUB_TYPE 1 SEGMENT SIZE 80,
    REGISTROS_AGRUPADOS   INTEGER DEFAULT 0,
    ESTAB_VENDA_ID        INTEGER,
    LOCAL_ESTOQUE_MIN_ID  INTEGER
);




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

ALTER TABLE TBTEMP_ITENS_PED_RESSUPRIMENTO ADD CONSTRAINT PK_TBTEMP_ITENS_PED_RESSUPRIMEN PRIMARY KEY (ID, RESSUPRIMENTO_ID);


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

CREATE INDEX ITBTEMP_ITENS_PED_RESSUPRIM_01 ON TBTEMP_ITENS_PED_RESSUPRIMENTO (ID);
CREATE INDEX ITBTEMP_ITENS_PED_RESSUPRIM_02 ON TBTEMP_ITENS_PED_RESSUPRIMENTO (RESSUPRIMENTO_ID);
CREATE INDEX ITBTEMP_ITENS_PED_RESSUPRIM_03 ON TBTEMP_ITENS_PED_RESSUPRIMENTO (ESTABELECIMENTO_ID);
CREATE INDEX ITBTEMP_ITENS_PED_RESSUPRIM_04 ON TBTEMP_ITENS_PED_RESSUPRIMENTO (LOCALIZACAO_ID);
CREATE INDEX ITBTEMP_ITENS_PED_RESSUPRIM_05 ON TBTEMP_ITENS_PED_RESSUPRIMENTO (REGISTROS_AGRUPADOS);
CREATE INDEX ITBTEMP_ITENS_PED_RESSUPRIM_06 ON TBTEMP_ITENS_PED_RESSUPRIMENTO (ESTAB_VENDA_ID);
CREATE INDEX ITBTEMP_ITENS_PED_RESSUPRIM_07 ON TBTEMP_ITENS_PED_RESSUPRIMENTO (LOCAL_ESTOQUE_MIN_ID);


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



SET TERM ^ ;



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



/* Trigger: TTBTEMP_ITENS_PED_RESSUP_B01I */
CREATE OR ALTER TRIGGER TTBTEMP_ITENS_PED_RESSUP_B01I FOR TBTEMP_ITENS_PED_RESSUPRIMENTO
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
    IF (NEW.ID IS NULL) THEN
        NEW.ID = GEN_ID(GTBTEMP_ITENS_PED_RESSUPRIMENTO, 1);
END
^

SET TERM ; ^



/******************************************************************************/
/****                         Fields descriptions                          ****/
/******************************************************************************/

COMMENT ON COLUMN TBTEMP_ITENS_PED_RESSUPRIMENTO.REGISTROS_AGRUPADOS IS 
'0 - Registros nao agrupados;
1 - Registos agrupados;';