CREATE OR ALTER trigger tbobrigacao_icms_b02i for tbobrigacao_icms
active before insert position 0
AS
DECLARE VARIABLE CODIGO VARCHAR(11);
BEGIN
   CODIGO = COALESCE((SELECT FIRST 1 A.CODIGO FROM TBOBRIGACAO_ICMS A WHERE A.CODIGO = NEW.CODIGO),'');
   IF(CODIGO <> '') THEN
   BEGIN
         EXCEPTION "..." ' CODIGO :'||NEW.CODIGO||' JA CADASTRADO!';
   END
END

CREATE OR ALTER trigger tbobrigacao_icms_b02u for tbobrigacao_icms
active before update position 0
AS
DECLARE VARIABLE CODIGO VARCHAR(11);
BEGIN
   CODIGO = COALESCE((SELECT FIRST 1 A.CODIGO FROM TBOBRIGACAO_ICMS A WHERE A.CODIGO = NEW.CODIGO AND A.ID <> NEW.ID),'');
   IF(CODIGO <> '') THEN
   BEGIN
         EXCEPTION "..." ' CODIGO :'||NEW.CODIGO||' JA CADASTRADO!';
   END
END
