Home > Database > Mysql Tutorial > MySQL获取当前AUTO_INCREMENT的ID_MySQL

MySQL获取当前AUTO_INCREMENT的ID_MySQL

WBOY
Release: 2016-06-01 13:48:00
Original
1199 people have browsed it

bitsCN.com
MySQL获取当前AUTO_INCREMENT的ID 获得新生成的AUTO_INCREMENT属性的值也有多种方法。推荐的方法是使用LAST_INSERT_ID()函数,
即在INSERT之后马上使用:   SELECT LAST_INSERT_ID();  另外还可以用"WHERE auto_col IS NULL"条件选择出新插入的行,即在INSERT后马上用:   SELECT * FROM t WHERE a IS NULL;     选择出来的将是新插入的行,而非真正的满足"a IS NULL"条件的行。但你要是再执行一次上述查询,
则返回的又变成了真正的满足"a IS NULL"条件的行,由于a是主键,因此肯定会返回空集。 这看上去很诡异是吗,不过MySQL也不想这么干,但ODBC标准里曾有这种用法,为了支持ODBC,
MySQL也是没办法啊。不过可以将SQL_AUTO_IS_NULL设为0来禁止这一用法。  bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template