/******************************************************************************/
/****              Generated by IBExpert 14/08/2023 14:42:07               ****/
/******************************************************************************/

/******************************************************************************/
/****     Following SET SQL DIALECT is just for the Database Comparer      ****/
/******************************************************************************/
SET SQL DIALECT 3;



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


CREATE GENERATOR GTBDRE_FIN_GRUPOS_FORMULA;

CREATE TABLE TBDRE_FIN_GRUPOS_FORMULA (
    ID                       INTEGER,
    DRE_FINANCEIRA_ID        INTEGER,
    DRE_FINANCEIRA_GRUPO_ID  INTEGER,
    OPERACAO                 VARCHAR(20),
    GRUPO_ID                 INTEGER,
    CLASSIFICACAO_GRUPO_ID   INTEGER,
    SQL_GRUPO_ID             INTEGER
);




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

CREATE INDEX ITBDRE_FIN_GRUPOS_FORMULA_01 ON TBDRE_FIN_GRUPOS_FORMULA (ID);
CREATE INDEX ITBDRE_FIN_GRUPOS_FORMULA_02 ON TBDRE_FIN_GRUPOS_FORMULA (DRE_FINANCEIRA_ID);
CREATE INDEX ITBDRE_FIN_GRUPOS_FORMULA_03 ON TBDRE_FIN_GRUPOS_FORMULA (DRE_FINANCEIRA_GRUPO_ID);


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



SET TERM ^ ;



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


/* Trigger: TITBDRE_FINANCEIRA_GRUPOS_FORMULA_B01I */
CREATE OR ALTER TRIGGER TITBDRE_FIN_GRUPOS_FORMULA_B01I FOR TBDRE_FIN_GRUPOS_FORMULA
ACTIVE BEFORE INSERT POSITION 0
as
begin
  if(new.id is null) then
    new.id = gen_id(GTBDRE_FIN_GRUPOS_FORMULA,1);
end
^

SET TERM ; ^



/******************************************************************************/
/****                             Descriptions                             ****/
/******************************************************************************/

COMMENT ON TABLE TBDRE_FIN_GRUPOS_FORMULA IS
'tabela de formulas personalizadas de grupos da DRE financeira';



/******************************************************************************/
/****                              Privileges                              ****/
/******************************************************************************/


/* Privileges of users */
GRANT ALL ON TBDRE_FIN_GRUPOS_FORMULA TO GC;
GRANT SELECT ON MON$ATTACHMENTS TO PUBLIC;
GRANT SELECT ON MON$CALL_STACK TO PUBLIC;
GRANT SELECT ON MON$CONTEXT_VARIABLES TO PUBLIC;
GRANT SELECT ON MON$DATABASE TO PUBLIC;
GRANT SELECT ON MON$IO_STATS TO PUBLIC;
GRANT SELECT ON MON$MEMORY_USAGE TO PUBLIC;
GRANT SELECT ON MON$RECORD_STATS TO PUBLIC;
GRANT SELECT ON MON$STATEMENTS TO PUBLIC;
GRANT SELECT ON MON$TABLE_STATS TO PUBLIC;
GRANT SELECT ON MON$TRANSACTIONS TO PUBLIC;

/* Privileges of roles */
GRANT ALL ON TBDRE_FIN_GRUPOS_FORMULA TO RDB$ADMIN;