Re: Can mSQL AUTO-INCREMENT a field with each INSERT to a table?

From: David J. Hughes (bambi@hughes.com.au)
Date: Wed Oct 06 1999 - 22:22:05 EST


On Mon, 4 Oct 1999, Christopher Stephens wrote:

> Sorry Greg, but I didn't understand this answer, apart from realising that
> what I want to do is possible (ie to turn an empty field in a large table
> into an ascending sequence of numbers).
> Can you give me concrete examples of how this would be done or point me at
> some appropriate documentation please?

Christopher,

If you have a table called 'staff' that you want to index using a unique,
sequential number, such as a staff ID, you'd use the following

        CREATE SEQUENCE ON staff

then you'd simply request the next sequence value each time you wanted to
enter a new record. eg.

        SELECT _seq from staff

        store this value into a variable called $seq for example

        INSERT INTO staff VALUES ($seq, '$firstName','$lastName' etc...

Each time you select the _seq field from a table that has a sequence
defined on it you'll get the next sequence value. It is an atomic
operation so you are assured of a correct sequence.

Bambi
...

-------------------------------------------------------------------------
To unsubscribe, go to http://www.Hughes.com.au/extras/email/



This archive was generated by hypermail 2b30 : Mon Mar 04 2002 - 09:03:51 EST