没有合适的资源?快使用搜索试试~ 我知道了~
首页轻松掌握MySQL函数中的last_insert_id()
轻松掌握MySQL函数中的last_insert_id()
2 下载量 93 浏览量
更新于2023-03-16
评论
收藏 56KB PDF 举报
前言 最近一个同事问我,为什么last_insert_id()得到的结果与预期的不一样呢,于是我就认真的去研究的一下这个参数,下面是关于last_insert_id()的详细介绍,一起来学习学习吧。 首先,举个例子 wing@3306>show create table tt; +-------+-----------------------------------------------------------------------------------------------------------------------+ | Table | Create Table
资源详情
资源评论
资源推荐
轻松掌握轻松掌握MySQL函数中的函数中的last_insert_id()
前言前言
最近一个同事问我,为什么last_insert_id()得到的结果与预期的不一样呢,于是我就认真的去研究的一下这个参数,下面是关
于last_insert_id()的详细介绍,一起来学习学习吧。
首先,举个例子首先,举个例子
wing@3306>show create table tt;
+-------+-----------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------+
| tt | CREATE TABLE `tt` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
# 没有指定值的时候,last_insert_id()符合预期希望
wing@3306>insert into tt values();
Query OK, 1 row affected (0.00 sec)
wing@3306>select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
wing@3306>insert into tt values();
Query OK, 1 row affected (0.00 sec)
wing@3306>select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
# what?不是应该是5么,为什么是第一个插入的值3?last_insert_id开始有一点不符合预期了。。
wing@3306>insert into tt values(),(),();
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
wing@3306>select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 3 |
+------------------+
1 row in set (0.00 sec)
wing@3306>insert into tt values(),(),();
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
wing@3306>select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 6 |
+------------------+
1 row in set (0.00 sec)
# 纳尼?按照预期不是10么?为什么还是之前的6?last_insert_id()我不懂你啊。。
wing@3306>insert into tt values(10);
Query OK, 1 row affected (0.01 sec)
wing@3306>select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 6 |
+------------------+
1 row in set (0.00 sec)
其次,研究一下其次,研究一下
查阅MySQL官方文档,真的太重要了。。。
官方出处:http://dev.mysql.com/doc/refman/5.6/en/information-functions.html#function_last-insert-id
官方文档原话:官方文档原话:
weixin_38596485
- 粉丝: 2
- 资源: 892
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0