List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:January 30 2002 12:47am
Subject:Re: next insert id
View as plain text  
At 15:33 -0800 1/29/02, James Montebello wrote:
>This result will be invalid when the a new row is written to the table,
>whether it's part of a transaction or not, no matter what the table type.
>I said as much, but perhaps I was a bit too cryptic.
>
>Generally speaking, getting this value reliably while other work is
>going on is only possible if you lock the table, do the select, do
>whatever you're going do to with that value, and unlock the table.
>As soon as you do the unlock, the value is useless.

Getting the value reliably is *exactly* what LAST_INSERT_ID() is
for.  No transaction necessary.

>
>james montebello
>
>On Tue, 29 Jan 2002, Christopher Thompson wrote:
>
>>  Not _necessarily_ true, surely, if there's another transaction active at
>>  the moment (assuming you are using a table that supports transactions)...?
>>
>>  At 03:16 PM 1/29/2002 -0800, James Montebello wrote:
>>
>>  >SELECT MAX(id) FROM table;
>>  >
>>  >will get you the highest value for 'id', that +1 will be the 'next' value,
>>  >until someone inserts a new row into that table.
>>  >
>>  >james montebello
>>  >
>>  >On Tue, 29 Jan 2002, Joel Wickard wrote:
>>  >
>>  > > database,sql,query,table
>>  > >
>>  > >
>>  > > 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?
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