UPDATE OR INSERT INTO TBMENU (CONTROLE, GRUPO, SUBGRUPO, TIPO, URL, DESCRICAO, DATAHORA)
                      VALUES (21260, 'FIS', 'FIS', '1   ', '', 'CADASTRO DE NCM', '2022-02-16 16:15:25')
                    MATCHING (CONTROLE);

COMMIT WORK;


SET TERM ^ ;

CREATE OR ALTER trigger ttbncm_secao_b02d for tbncm_secao
active before delete position 0
AS
BEGIN
   IF(OLD.SECAO > 0) THEN
   BEGIN
      DELETE FROM TBNCM_CAPITULO WHERE SECAO = OLD.SECAO;
   END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_b01i for tbncm
active before insert position 0
as
begin
  if (new.codigo is null) then
    new.codigo = gen_id(gtbncm,1);
end
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_capitulo_b02d for tbncm_capitulo
active before delete position 0
AS
BEGIN
   IF(OLD.CAPITULO > 0) THEN
   BEGIN
      DELETE FROM TBNCM WHERE CAPITULO = OLD.CAPITULO;
   END
END
^

SET TERM ; ^

