MySQL Forums
Forum List  »  Other Migration

Re: Replacing Sequences
Posted by: Nick Roper
Date: July 19, 2004 04:44PM

Hi Rick,

See the following from the MySQL Reference Manual:

--------------------------------------------------------------------------------
You can retrieve the most recent AUTO_INCREMENT value with the LAST_INSERT_ID() SQL function or the mysql_insert_id() C API function. These functions are connection-specific, so their return value is not affected by another connection also doing inserts.

Note: For a multiple-row insert, LAST_INSERT_ID()/mysql_insert_id() will actually return the AUTO_INCREMENT key from the first of the inserted rows. This allows multiple-row inserts to be reproduced correctly on other servers in a replication setup.
-------------------------------------------------------------------------------

See http://dev.mysql.com/doc/mysql/en/example-AUTO_INCREMENT.html for more details.

As you will see, the values are connection specific, so they should return the last auto increment value from your session. The functions behave slighly differently with regard to return values for inserts that don't use NULL to generate an auto-increment (e.g. by inserting a specific value into the auto-increment column)

See http://dev.mysql.com/doc/mysql/en/mysql_insert_id.html for details on how the native MySQL and C API functions differ.

Which version of MySQL are you using, if it's 4.x + then you might be able to do the whole thing with a multiple table update statement, but it's a bit late in the day to get my head round it right now.

Cheers,

Nick

--
Nick Roper

Options: ReplyQuote


Subject
Views
Written By
Posted
3973
July 19, 2004 01:13PM
3069
July 19, 2004 02:10PM
3010
July 19, 2004 02:30PM
Re: Replacing Sequences
2994
July 19, 2004 04:44PM
2564
July 19, 2004 04:46PM
2763
July 19, 2004 04:49PM
2579
July 19, 2004 05:01PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.