Follows the query to get the next ID:
SELECT AUTO_INCREMENT
FROM information_schema.tables
WHERE table_name = 'nome_da_tabela'
AND table_schema = DATABASE();
Or one of these:
SHOW TABLE STATUS FROM nome_da_base_de_dados LIKE 'nome_da_tabela';
SHOW TABLE STATUS FROM nome_da_base_de_dados WHERE Name='nome_da_tabela';
Note that these darlings are very specific, probably only serving in Mysql. The option with SHOW TABLE STATUS
returns multiple columns, between them the next auto-increment.
An alternative would be you give an UPDATE on the line you just inserted, using the column id
+ 1, which gives in the same to obtain the last_insert_id()
.
Anyway, it is worth saying that probably this solution that you are looking for sooner or later will give problem, either by failure in insertion, two users trying to insert almost at the same time, or even the simple data mismatch at the time of some removal.
I can’t say this, because you didn’t give details of what you’re doing, but by the initial question, I have a slight feeling that whatever you’re trying to do, there may be other ways to resolve.
If it is in the bank, just create an entire field with
auto_increment
, that the bank does it automatically,– user28595