MySQL can obtain the ID of the current AUTO_INCREMENT to obtain the value of the newly generated AUTO_INCREMENT attribute. The recommended method is to use the LAST_INSERT_ID () function,
That IS, use SELECT LAST_INSERT_ID () immediately after the INSERT statement. You can also use the "WHERE auto_col is null" condition to SELECT the newly inserted row, that IS, immediately after the INSERT statement: SELECT * FROM t WHERE a is null; the row selected by www.2cto.com IS a newly inserted row instead of a row that truly meets the "a is null" condition. However, if you execute the preceding query again,
Then, the returned row becomes a row that meets the "a is null" condition. Because a IS the primary key, it will certainly return an empty set. It seems strange, though, MySQL does not want to do this either. However, this is a practice in the ODBC standard. To support ODBC,
There is no way for MySQL. However, you can set SQL _AUTO_IS_NULL to 0 to disable this usage.