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() 和并发


- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01