Subject | Re: [firebird-support] Complex generators? |
---|---|
Author | Florian Hector |
Post date | 2003-12-28T09:09:55Z |
> Is there a (nice) way of implementing this behaviour? My ideal caseCreate Trigger ADD_ID for MyTable
> would be without using generators, because the TYPE field is also
> dynamic (and CREATE GENERATOR doesn't work inside a trigger, also...)
>
>
active before insert position 0
as
Declare Variable ID Integer;
begin
Select Max(id) from MyTable WHERE TYPE=NEW.TYPE into :ID;
NEW.ID = :ID + 1;
end
I take it that you are aware of the possible problems that can bring. But if you create a unique
index on Type+ID, the server doesn't let you insert rows with the same combination of Type and ID.
Florian