[KLUG Members] Sequences & MySQL
Jamie McCarthy
jamie at mccarthy.vg
Wed Apr 13 08:23:27 EDT 2005
awilliam at whitemice.org (Adam Tauno Williams) passes along the
question:
> As far as I can see the only option is to create a helper table
> which contains one otherwise unused record for each unique key.
> Creating a new key would imply inserting a record in the helper
> and retrieving the auto-increment value (which is then used in
> the real tables).
>
> Obviously this is kinda fragile, so maybe someone knows a better
> workaround? :-|
That's the recommended way to implement sequences:
http://dev.mysql.com/doc/mysql/en/information-functions.html
(scroll down to "LAST_INSERT_ID")
In practice, there's no reason for the table that holds the sequence
counter to be empty: one may as well put real data into it, too.
I'm afraid I don't understand how this is any more "fragile" than
any other way...
--
Jamie McCarthy
http://mccarthy.vg/
jamie at mccarthy.vg
More information about the Members
mailing list