Subject Re: [firebird-support] Delete trigger trickery
Author emel.hu
sdbeames wrote:
> G'day all,
>
> Is there anything wrong with this trigger....
>
> CREATE TRIGGER LEVELS_TG_BD FOR LEVELS
> BEFORE DELETE
> AS
> begin
> if (exists(select 1 from JOBS where LVL = old.LVL)) then
> exception CANT_DELETE_LEVEL;
> end^
>
> The exception fires every time I try to delete a row from LEVELS,
> even when there's patently no JOBS entry using that LEVEL.

Use a 'debug' trick (for examle):

CREATE TRIGGER LEVELS_TG_BD FOR LEVELS
BEFORE DELETE
AS
declare variable ID integer;
begin
select ID from JOBS where LVL = old.LVL
into ID;

if (ID not NULL) then
exception CANT_DELETE_LEVEL ' [ID=' || ID || ']';
end^

If you know what row exists, maybe will found the causer.

eMeL

ps: sorry my terrible english...