ALTER TABLE TBVINCULO
    ADD STATUSVINCULO INTEGER DEFAULT 0;

CREATE OR ALTER trigger tbarquivo_bi0 for tbarquivo
active before insert position 0
as
declare variable Valor Numeric(15,5);
begin

    valor = Coalesce((


        select a.id from tbarquivo a where
        a.arquivo = new.arquivo and a.usuario_id = new.usuario_id
        and((dateadd(second, 15, a.datahora)) >= new.datahora)


    ),0);

    if (valor > 0) then
    Begin

    Exception "..." 'Duplicado';
    End

End;

CREATE OR ALTER trigger tbvinculo_bi0 for tbvinculo
active before insert position 0
as
declare variable Valor Numeric(15,5);
begin

    valor = Coalesce((


        select a.id from tbvinculo a where
        a.usuario_id = new.usuario_id and a.tabela_id= new.tabela_id and a.tabela = a.tabela and a.observacao = new.observacao
        and((dateadd(second, 15, a.datahora)) >= new.datahora)


    ),0);

    if (valor > 0) then
    Begin

    Exception "..." 'Duplicado';
    End

End;
