Re: Serial Datatypes
Posted in 1996
Vikram wrote: > > To all : > > I am trying to insert rows into three tables A, B & C in one > transaction. > > Table A contains a serial field. (Say the last row inserted has a value > 100 in this field) > > Now if for some reason a transaction is rolled back, the serial field > also should be rolled back. > > But when I try to insert the next transaction successfully, the serial > field contains 102 and not 101. > > Is this a bug or what ?? No, As I wrote in an earlier article, the Serial field is kept in the Index file of the table. Its a 4 byte word starting around byte 40 or so. (I forget) Anyways, the purpose of the serial field is to ensure that the record is unique, nothing more. Using dejanews, here is a copy of my earlier posting. Hope this helps! -Mikey =============================================================== 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 ;-)