Friends, I come to you to find out who tells me how to know the auto_increment of a table.
Let's say you id_campo
have 30 values, but after about 6 rows are deleted, it would stay at id_campo (24)
, but the auto_increment is at 31.
Is there a way to get that auto_increment(31)
with SQL query without having to create another table that saves the last auto_increment value of the main table?
You can run the following query.
If what you want is to get the last value of an auto-incrementing field, not the value that is in memory in information_schemes, it would be better to use the query that does the same
InnoDB
.Given:
r_categoria
id_categoria
We run this query:
The query would return the id of the last existing value.
If you want to get the value of an upcoming new value, it would just be a matter of adding one to it:
In that case, this query will be more performant than having to read the
INFORMATION.SCHEMES
, it acts directly on the table.According to the documentation , that's how InnoDB initializes the auto-incrementing counter:
This operation IS NOT FUNCTIONAL.
It turns out that if a record is deleted in the table, for the engine as such, it does not take it into account and continues with the ID that it is supposed to follow, then that is when that method will not work for us.