MySQL: Get next auto increment value of a table

Some time ago, I needed to get the auto increment value for the next inserted row in a MySQL table.

As the first solution, I was thinking to get maximum of ‘id’ field and then increment it for next inserted record like,

But it is not a right way to do this because auto increment values use unique ids.

By doing some research, I found a solution for this problem. You can use “SHOW TABLE STATUS” query like,

This command returns a two dimentional array with “Auto_increment” value.

There is another solution for this. You could use direct select query like,

Hope this will help.

You may also like...