Hibernate and other persistence tools can obtain the persistent object after saving, and the id inside is the id just inserted. If there is no persistence layer, you can also use the SQL function LAST_INSERT_ID() to obtain the ID value of the AUTO_INCREACE field just inserted. The previous SQL must be an INSERT statement. If it is another statement, the returned ID value is zero.
Assuming that the poster uses the best language in the world, then you can use the mysql_insert_id() function
Hibernate and other persistence tools can obtain the persistent object after saving, and the id inside is the id just inserted.
If there is no persistence layer, you can also use the SQL function LAST_INSERT_ID() to obtain the ID value of the AUTO_INCREACE field just inserted. The previous SQL must be an INSERT statement. If it is another statement, the returned ID value is zero.
https://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
Read comments
Only talk about mysql
Some database drivers will provide specialized methods, such as
PDO::lastInsertId