MYSQL last_insert_id() and concurrency(MYSQL last_insert_id() 和并发)
问题描述
我有一个简单的 MYSQL 问题.如果我在一个网页上运行 INSERT QUERY 之后立即执行包含 LAST_INSERT_ID() 的查询,该网页有许多并发用户访问执行 INSERT的其他页面strong>LAST_INSERT_ID() 的值是否会被掺假/损坏?
I have a simple MYSQL question. If I make a query that contains LAST_INSERT_ID() right after an INSERT QUERY running on a web page which has many concurrent users accessing other pages that perform INSERT operations would the value of LAST_INSERT_ID() be adulterated/corrupted?
推荐答案
不,它会从当前连接返回插入 id.只要您的脚本没有进行任何其他插入,您就会得到您想要的.
No, it will return the insert id from the current connection. As long as your script hasn't made any other inserts, you will get the one you want.
另请注意,这只会返回生成的 ID(例如自动增量).如果您创建自己的 ID,它不会返回给您.
Also be aware that this will only return a generated ID (e.g. an auto-increment). If you are creating your own ID's it won't return this to you.
这篇关于MYSQL last_insert_id() 和并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MYSQL last_insert_id() 和并发
基础教程推荐
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
