I have a mysql table with an auto increment field. I am using the auto increment counter as an id generator across the database.
I need a way to increment the counter, get the new number but without inserting any data.
Is there an easy to do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are using it as an ID generator, then (aside from altering the table) you’ll have to insert something to get the next value.
The easiest way to do this without inserting any data would be to do an
INSERTfollowed by callingLAST_INSERT_IDfollowed by issuing aROLLBACK. That will rollback the insert, but the next ID will still be incremented.