SET TERM ^ ;

CREATE OR ALTER trigger ttbncm_secao_b02i for tbncm_secao
active before insert position 0
AS
DECLARE VARIABLE CODIGO VARCHAR(11);
BEGIN
   CODIGO = COALESCE((SELECT A.SECAO FROM TBNCM_SECAO A WHERE A.SECAO = NEW.SECAO),'');
   IF(CODIGO <> '') THEN
   BEGIN
         EXCEPTION "..." ' SEÇÃO: '||NEW.SECAO||' JÁ CADASTRADA!';
   END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_capitulo_b02i for tbncm_capitulo
active before insert position 0
AS
DECLARE VARIABLE CODIGO VARCHAR(11);
BEGIN
   CODIGO = COALESCE((SELECT A.CAPITULO FROM TBNCM_CAPITULO A WHERE A.CAPITULO = NEW.CAPITULO),'');
   IF(CODIGO <> '') THEN
   BEGIN
         EXCEPTION "..." ' CAPITULO: '||NEW.CAPITULO||' JÁ CADASTRADO!';
   END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbncm_b03i for tbncm
active before insert position 0
AS
DECLARE VARIABLE CODIGO VARCHAR(11);
BEGIN
   CODIGO = COALESCE((SELECT A.NCM FROM TBNCM A WHERE A.NCM = NEW.NCM),'');
   IF(CODIGO <> '') THEN
   BEGIN
         EXCEPTION "..." ' NCM: '||NEW.NCM||' JÁ CADASTRADO!';
   END
END
^

SET TERM ; ^

ALTER TRIGGER TTBNCM_SECAO_B02I INACTIVE;
ALTER TRIGGER ttbncm_capitulo_b02i INACTIVE;
ALTER TRIGGER ttbncm_b03i INACTIVE;

