关羽 LAST_INSERT_ID() 显示的数据问题
用下面的语句创建了一个新表
create table child_list (chilNo char(2),id int primary key auto_increment,name char(10),age CHAR(2),sex char(5));
然后插入 insert into child_list(chilNo,name,age) values (LAST_INSERT_ID(),'Tom',17);
然后表中显示是这样的

很奇怪这里为什么是 3,然后继续插入两条数据
insert into child_list(chilNo,name,age) values (LAST_INSERT_ID(),'Jimmy',17);
insert into child_list(chilNo,name,age) values (LAST_INSERT_ID(),'King',19);
这个时候表中的显示是这样的,可以看出从第二条记录开始才是按插入顺序开始排列,那么想咨询一下第一条插入后产生的那个3表示什么意思呢,谢谢

create table child_list (chilNo char(2),id int primary key auto_increment,name char(10),age CHAR(2),sex char(5));
然后插入 insert into child_list(chilNo,name,age) values (LAST_INSERT_ID(),'Tom',17);
然后表中显示是这样的

很奇怪这里为什么是 3,然后继续插入两条数据
insert into child_list(chilNo,name,age) values (LAST_INSERT_ID(),'Jimmy',17);
insert into child_list(chilNo,name,age) values (LAST_INSERT_ID(),'King',19);
这个时候表中的显示是这样的,可以看出从第二条记录开始才是按插入顺序开始排列,那么想咨询一下第一条插入后产生的那个3表示什么意思呢,谢谢

...全文
相关推荐
Mysql中LAST_INSERT_ID()的函数使用详解
如果你先向表A插入数据,然后向表B插入数据,LAST_INSERT_ID()将返回表B中最后插入的ID值。3.
解决Hibernate JPA中insert插入数据后自动执行select last_insert_id()
总的来说,如果你在使用Hibernate JPA时遇到了插入数据后自动执行`select last_insert_id()`的问题,检查`hibernate.temp.use_jdbc_metadata_defaults
java获取新insert数据自增id的实现方法
幸运的是,我们可以通过select LAST_INSERT_ID()这个操作来解决这个问题。select LAST_INSERT_ID()是线程安全的,也就是说它是具体于数据库连接的。
轻松掌握MySQL函数中的last_insert_id()
如果在不同的连接或会话中插入数据,`last_insert_id()` 会返回各自连接或会话的最新ID。
在Spring中用select last_insert_id()时遇到问题
然而,当在Spring中尝试使用`SELECT LAST_INSERT_ID()`时,可能会遇到问题,因为Spring的事务管理机制和数据库连接池的影响。


