The Secret of Serial Fields
Posted in 1996
Malcolm Weallans wrote: > > I'd always assumed that INFORMIX added 1 to the MAX value of an index and > pre-set this value when the table was generated. Reading the manuals > does not give any help on this. Perhaps somebody from INFORMIX should > tell us how it's done. > ****************************************************** WARNING! ****************************************************** The following information may be proprietary information. Read at your own risk. #include <std.disclaimer.h> This information does not come from Informix. It was gained from reverse engineering an Informix Database. Its validity and my sanity are questionable. For specifics, please e-mail me. The serial seed is stored in the index for a given table. When a table is created with a serial column, the seed value takes the value of the specified initial value. If none is specified the value is set to 1. When a row is inserted in to a table, the following logic takes place: Defininitions: I = Input serial value S = Seed value IF (I = 0) THEN LET I = S++ ELSE IF (I > S) THEN LET S = I + 1 END IF END IF PERFORM INSERT USING I Note: That it is possible to have the insert fail. Even if the insert fails, the serial value is incremented. I hope that this clears things up. Just a few little tips from your Uncle Mike ;-)