Get current AUTO_INCREMENT value for any table Get current AUTO_INCREMENT value for any table mysql mysql

Get current AUTO_INCREMENT value for any table


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.TABLESWHERE TABLE_SCHEMA = 'DatabaseName'AND   TABLE_NAME   = 'TableName';


If you just want to know the number, rather than get it in a query then you can use:

SHOW CREATE TABLE tablename;

You should see the auto_increment at the bottom


I believe you're looking for MySQL's LAST_INSERT_ID() function. If in the command line, simply run the following:

LAST_INSERT_ID();

You could also obtain this value through a SELECT query:

SELECT LAST_INSERT_ID();