List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:January 30 2002 1:01am
Subject:Re: next insert id
View as plain text  
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. :-)
Thread
next insert idJoel Wickard30 Jan
  • Re: next insert idJames Montebello30 Jan
    • Re: next insert idNathan30 Jan
      • Re: next insert idChristopher Thompson30 Jan
    • Re: next insert idChristopher Thompson30 Jan
      • Re: next insert idJames Montebello30 Jan
        • Re: next insert idPaul DuBois30 Jan
    • Re: next insert idPaul DuBois30 Jan
      • Re: next insert idJames Montebello30 Jan
        • RE: next insert idRoger Baklund30 Jan
        • Re: next insert idPaul DuBois30 Jan
  • RE: next insert idJohnny Withers30 Jan
    • Re: next insert idlaszlo30 Jan
      • Re: next insert idPaul DuBois30 Jan
  • Re: next insert idPaul DuBois30 Jan
    • Re: next insert idPaul DuBois30 Jan
      • Re: next insert idJames Montebello30 Jan
        • Re: next insert idPaul DuBois30 Jan
        • Re: next insert idDL Neil30 Jan
          • Re: next insert id (slightly OT)William R. Mussatto30 Jan
            • Re: next insert id (slightly OT)DL Neil30 Jan
              • Re: next insert id (slightly OT)William R. Mussatto30 Jan