Subject Re: [firebird-support] Help with Trigger
Author Helen Borrie
At 01:44 PM 16/07/2004 +0200, you wrote:
>I would like to create a trigger(Before Insert) on table A,
>that will select a date in table B. And if the date in table A
>is bigger than the date in B, disallow the current insert into A.
>Can anyone please help me with the syntax.
>The body should be something like:
> select BDate from B where =;
> if (B.BDate <= new.ADate) CANCELINSERT

You can't use an Insert trigger to cancel an insert!! What you can do is
raise an exception, which will pass control back to the application. The
application can listen for the exception and take whatever steps are
necessary to prevent the insertion from happening.


create exception invalid_date 'Blah';

create trigger....

declare vali_date date;
select BDate from B where =
into :vali_date;
if (vali_date <= new.ADate) then
exception invalid_date 'Date must be later than '||cast (:vali_date as