Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I find out the next auto_increment to be used?

Tags:

mysql

Is it possible to find out what the next auto increment will be for my primary key without executing an INSERT INTO query? Some rows are deleted meaning that it's not as easy as just adding one to a SELECT MAX query on the PK. Many thanks.

like image 781
user114671 Avatar asked Feb 08 '12 10:02

user114671


1 Answers

If you really want to know next auto_increment value try SHOW TABLE STATUS returns next Auto_increment field, e.g.:

SHOW TABLE STATUS WHERE name = your_table_name;

or

SELECT Auto_increment
FROM information_schema.tables
WHERE table_schema = DATABASE() AND table_name = your_table_name
like image 67
Michał Powaga Avatar answered Oct 11 '22 16:10

Michał Powaga