Subject | Re: Auto-increment and generators |
---|---|
Author | Svein Erling |
Post date | 2004-02-11T10:54:49Z |
> INSERT INTO TEST (ID) VALUES (2); SET GENERATOR g1 TO 3;Close, but not quite. Change your insert trigger to do this if a value
> INSERT INTO TEST (ID) VALUES (1); SET GENERATOR g1 TO 2;
> INSERT INTO TEST (DATA) VALUES (NULL); /* oops */
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