Subject Re: Auto-increment and generators
Author Svein Erling
> INSERT INTO TEST (ID) VALUES (2); SET GENERATOR g1 TO 3;
> INSERT INTO TEST (ID) VALUES (1); SET GENERATOR g1 TO 2;
> INSERT INTO TEST (DATA) VALUES (NULL); /* oops */

Close, but not quite. Change your insert trigger to do this if a value
is supplied:

INSERT INTO TEST (ID) VALUES (:ID);
a = (GEN_ID(g1, 0)
if (a < ID) THEN GEN_ID(g1, ID - a)

This avoids using DDL and only increments the generator, never
decrements. Potential problems arises only if someone decides to
insert a very high value for ID, making the generator 'roll over'.

Note that the syntax is not 100% correct (at least I write very few
triggers and have not checked what I wrote)

HTH,
Set
- I support Firebird, I am a FirebirdSQL Foundation member.
- Join today at http://www.firebirdsql.org/ff/foundation