I considered the top google results, almost all functions of mysql and etc... Unfortunately, as far as I learned, without adding a new row into the table of a database, we can't know the next primary key. Please, say me I'm wrong. How can't there be any solution for this problem? I am disappointed.
答案 0 :(得分:2)
Took about 7 seconds to find on Google: https://www.bram.us/2008/07/30/mysql-get-next-auto_increment-value-fromfor-table/
SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = "databaseName"
AND TABLE_NAME = "tableName"
答案 1 :(得分:2)
The value is present in INFORMATION_SCHEMA.TABLES
(see here). Under reasonable assumptions, you can get the value there.
Reasonable assumptions:
答案 2 :(得分:0)
with this request you have the last id in your table
SELECT MAX(id) FROM your_table
You can just add +1 to your request result.