mysql last_insert_id();

来源:互联网 发布:linux mint 输入法 编辑:程序博客网 时间:2024/04/29 21:16

->insert into t5(name) values('chuan'),('test'),('an');
->select last_insert_id();


还有个问题就是如果insert into是用类似上面的格式多条记录同时插入。没插入之前id为10 插入三条记录后id为13
可是这select last_insert_id();却只能得到11而不是13
因为假如你使用一条INSERT语句插入多个行,  LAST_INSERT_ID() 只返回插入的第一行数据时产生的值。
所以个人觉得还是用select max(id) from table_name 比较保险,毕竟id是auto_increment的。

原创粉丝点击