MYSQL last_insert_id() 和并发

MYSQL last_insert_id() and concurrency(MYSQL last_insert_id() 和并发)
本文介绍了MYSQL last_insert_id() 和并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 MYSQL 问题.如果我在一个网页上运行 INSERT QUERY 之后立即执行包含 LAST_INSERT_ID() 的查询,该网页有许多并发用户访问执行 INSERTLAST_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() 和并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)