CREATE OR ALTER trigger ttbrefeicao_terceiros_b02i for tbrefeicao_terceiros
active before insert position 0
AS
DECLARE VARIABLE VALIDAR VARCHAR(500);
BEGIN
    VALIDAR = COALESCE((SELECT FIRST 1
                    T.CODIGO
                FROM TBREFEICAO_TERCEIROS T
                WHERE T.CODIGO = NEW.CODIGO),0);

    IF(VALIDAR > 0) THEN
    BEGIN
        EXCEPTION "..." 'CODIGO JA EXISTENTE';
    END
END;

CREATE OR ALTER trigger ttbrefeicao_terceiros_b0u1 for tbrefeicao_terceiros
active before update position 0
AS
DECLARE VARIABLE VALIDAR VARCHAR(500);
BEGIN
    VALIDAR = COALESCE((SELECT FIRST 1
                    T.CODIGO
                FROM TBREFEICAO_TERCEIROS T
                WHERE T.CODIGO = NEW.CODIGO),0);

    IF(VALIDAR > 0 AND NEW.CODIGO <> OLD.CODIGO) THEN
    BEGIN
        EXCEPTION "..." 'CODIGO JA EXISTENTE';
    END

END;

