MySQL obtains the ID of the current AUTO_INCREMENT

Source: Internet
Author: User


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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.