Re: How to get next serial value
Posted in 1997
Sally Woolrich <sally.woolrich@exxcelsis.co.uk> wrote: :In article <340a6716.1325636@gate.idg.no>, Nils Myklebust :<Nils.Myklebust@idg.no> writes ...snip... :>2. You can use the mechanism in 1. to implement a sequence generator :>using a table that contains nothing but one column of type serial. You :>insert into this table first and retreive the serial number as above. :>You can delete all rows in this table after every insert if you want, :>so the table never grows. This can all be easily implemented as a :>stored procedure so it would work more or less exactly like your :>description of the Oracle unique number generator. : :But you then need to make sure that two processes don't pick up the same :number with (almost) concurrent reads, which would mean using LOCKs in :such a way that the whole application doesn't end up with lots of hangs :waiting for the process with the lock to release it. Hi Sally I don't quite see what you mean here. Does this refer to the above suggestion for implementing a sequence number generator? In that case I can see no way it can generate the same number twice even when two or more processes use it concurrently. There should be no need for any special locking for this purpose as only simple inserts are done. :Just letting Informix put on the number & then picking it up solves this :problem. If what you need is solved by a simple serial column in your table one should of course allways simply insert and pick up the serial value afterwards if it's needed for some purpose. The serial number generator is for cases where one need separate unique sequences within the same table, a unique sequence over several tables or possibly need to add something like a check digit to the serial value. Nils.Myklebust@idg.no NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company The Informix FAQ is at http://www.iiug.org