MySQL Forums
Forum List  »  Newbie

Re: Get Number and Increment
Posted by: Phillip Ward
Date: July 09, 2020 07:30AM

Quote

Do I need to surround it with a Transaction ?

I would recommend doing so, but it's not strictly necessary because you're updating the value before selecting it, which will implicitly take a lock on the record.

begin transaction ; 

   update tableName 
   set myField = myField + 1 ;

   select myField 
   from tableName ; 

commit ;

Please tell me there's only one record in this table ...

Also: last_insert_id() returns the last, auto-increment value generated by an insert statement.

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
July 09, 2020 04:53AM
Re: Get Number and Increment
July 09, 2020 07:30AM


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.