CREATE TABLE TBDRE_GERENCIAL_HISTORICO_MES (
    ID INTEGER NOT NULL,
    ANO INTEGER,
    MES INTEGER,
    DRE_ID INTEGER,
    DADOS BLOB SUB_TYPE 1 SEGMENT SIZE 80,
    DATAHORA_UPDATE TIMESTAMP DEFAULT 'now');

ALTER TABLE TBDRE_GERENCIAL_HISTORICO_MES
ADD CONSTRAINT PK_TBDRE_GERENCIAL_HISTORICO_ME
PRIMARY KEY (ID);

CREATE SEQUENCE GTBDRE_GERENCIAL_HIST_MES;

create trigger ttbdre_gerencial_hist_mes_b01I for tbdre_gerencial_historico_mes
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbdre_gerencial_hist_mes,1);
end;

CREATE trigger tbdre_gerencial_hist_mes_b01u for tbdre_gerencial_historico_mes
active before update position 0
AS
begin
  new.datahora_update = current_timestamp;
end;

CREATE INDEX ITBDRE_GERENCIAL_HIST_01
ON TBDRE_GERENCIAL_HISTORICO_MES (ANO,MES,DRE_ID);

ALTER TABLE TBDRE_GERENCIAL_HISTORICO_MES
    ADD FLAG COMPUTED BY (cast(ANO||mes as integer));

CREATE INDEX ITBDRE_GERENCIAL_HIST_02
ON TBDRE_GERENCIAL_HISTORICO_MES COMPUTED BY (cast(ANO||mes as integer));

