The original question that started this thread was:

>>
>>I need to find out what the next value will be in an auto_increment field
>>will be. could someone help me out with the select statement?

To which I replied:

>
>You can't find out what it *will be* until you actually create the record.
>Then you get the like this:
>
>SELECT LAST_INSERT_ID();
>
>Check the discussion for LAST_INSERT_ID() in the MySQL manual.
>
>It will tell you the answer to your next question. :-)

When I wrote that last sentence, I was anticipating that the original
poster would ask, "but what happens if other clients insert records
and generate new AUTO_INCREMENT values?  Won't that cause the value
returned by LAST_INSERT_ID() to become invalid?"

The answer, of course, is no.  LAST_INSERT_ID() is designed specifically
*not* to be affected by activity performed by other clients.  It's all
spelled out in the manual.  If you don't believe it (and from the amount
of traffic that this thread has generated, apparently many people do not),
here's the reference:

http://www.mysql.com/doc/M/i/Miscellaneous_functions.html


LAST_INSERT_ID() is your friend.  Get to know it, it won't let you down. :-)

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to