1. Select Max (ID) from TableName
2.SELECT last_insert_id () function
LAST_INSERT_ID is not related to table, last_insert_id will change if data is inserted into table A, and then the data is injected into form B.
Max (ID) is obviously not available in the case where multiple users are alternately inserting data. It's time to use last_insert_id because last_insert_id is connection based, as long as each thread uses a separate connection object, Last_insert_ The ID function returns the ID of the first record generated by the connection for the latest insert or update operation on the Auto_increment column. This value cannot be affected by other clients (Connection), which guarantees that you will be able to retrieve your ID without worrying about other clients ' activities and do not need to lock. Insert multiple records using a single INSERT statement, LAST_INSERT_ID returns a list.
3. SELECT @ @IDENTITY;
@ @identity is a system-defined global variable that represents the last time the value of the self-increment column for inserting data into a table with the identity attribute (that is, the self-increment column). General system-defined global variables start with @@ 开头 and user-defined variables begin with @.
For example, there is a table A, its self-increment column is an ID, when inserting a row of data into a table, if the value of the self-increment after inserting data automatically increases to 101, then the value obtained by the SELECT @ @identity is 101. The @ @identity is used only if the connection is not closed when the insert operation is executed, or a null value is obtained.
4. SHOW TABLE STATUS;
The result is a auto_increment field in the corresponding table name record, and the value of the next self-increment ID is the maximum self-increment ID of the current table.
How MySQL obtains system self-increment ID information