MySQL: Get next AUTO_INCREMENT value from/for table

Note to self: To get the next auto_increment value from a table run this query: SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = $dbName AND TABLE_NAME = $tblName. Don’t forget it (again).

Elsewhere

6 Responses to MySQL: Get next AUTO_INCREMENT value from/for table

  1. wiki says:

    MAN! THANKS FOR THIS!!!
    i am searching this from years!!!!!!!

  2. And for the record, if you want to change the auto_increment, issue the statement:

    alter table tablename auto_increment = newvalue

  3. David says:

    Hahahahahahahaha!!! I really laughed hard when I read that! “Don’t forget it (again).” Hehehe.

    But seriously, thanks a million, i’ve been using count() + 1 for years!! shame on me :)

  4. Malinda says:

    thanks lot , i searched hundred of sites

  5. rakesh says:

    excellent :)
    i was doing +1 method :)
    but this really rocks
    super cool

  6. septianw says:

    nice!!!!
    I should know this method.
    let me bookmark this, and repost to my blog with backlink of course.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>