Search code examples
mysqlauto-increment

Get current AUTO_INCREMENT value for any table


How do I get the current AUTO_INCREMENT value for a table in MySQL?


Solution

  • You can get all of the table data by using this query:

    SHOW TABLE STATUS FROM `DatabaseName` WHERE `name` LIKE 'TableName' ;
    

    You can get exactly this information by using this query:

    SELECT `AUTO_INCREMENT`
    FROM  INFORMATION_SCHEMA.TABLES
    WHERE TABLE_SCHEMA = 'DatabaseName'
    AND   TABLE_NAME   = 'TableName';