当前位置:网站首页>MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
2022-07-05 12:54:00 【Java technology stack】
source :cnblogs.com/yjmyzz/p/13562182.html
In the business system , Use update Statement updating data is a normal scenario , We often pass through update Number of rows updated , To make some business judgments , Similar to the following pseudo code :(mybatis + mysql scene )
if (xxxMapper.updateByPrimaryKeySelective(entity)>0){
// The update is successful , Do other business processing
}
But there's a hole ,mysql in update Number of rows affected >0 It's conditional , If there is a table :
There's only one record in it (ID=1), We use it update Update one ID=1 This record of
This line was successfully updated , The number of affected lines is 1, Taken for granted , Then put this update Statement again :
Now , The number of affected rows returned is 0, in other words , When the record to be updated is the same as the old value of the original record ,mysql In fact, there will be no update ..
In other words , If the data transmitted from the upstream , Equal to the old value of the database itself , When there is no change ,update The number of lines affected by the statement is 0. This is different from another scenario :" Update a record that doesn't exist , Affect the number of rows and return 0" Indistinguishable .
Conclusion : Do not use update The number of lines affected by the statement makes important business judgments !
Recent hot article recommends :
1.1,000+ Avenue Java Arrangement of interview questions and answers (2022 The latest version )
2. Explode !Java Xie Cheng is coming ...
3.Spring Boot 2.x course , It's too complete !
4. Don't write about the explosion on the screen , Try decorator mode , This is the elegant way !!
5.《Java Development Manual ( Song Mountain version )》 The latest release , Download it quickly !
I think it's good , Don't forget to like it + Forward !
边栏推荐
- 深度长文探讨Join运算的简化和提速
- Taobao short video, why the worse the effect
- 滴滴开源DELTA:AI开发者可轻松训练自然语言模型
- Iterator details in list... Interview pits
- SAP SEGW 事物码里的 ABAP Editor
- MySQL 巨坑:update 更新慎用影响行数做判断!!!
- Pinduoduo flag insertion remarks API
- UNIX socket advanced learning diary -ipv4-ipv6 interoperability
- From the perspective of technology and risk control, it is analyzed that wechat Alipay restricts the remote collection of personal collection code
- SAP UI5 ObjectPageLayout 控件使用方法分享
猜你喜欢
【云原生】Nacos中的事件发布与订阅--观察者模式
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces
A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
Taobao flag insertion remarks | logistics delivery interface
SAP SEGW 事物码里的 ABAP 类型和 EDM 类型映射的一个具体例子
实战模拟│JWT 登录认证
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
Super efficient! The secret of swagger Yapi
What if wechat is mistakenly sealed? Explain the underlying logic of wechat seal in detail
RHCSA7
随机推荐
Setting up sqli lab environment
实战模拟│JWT 登录认证
SAP self-development records user login logs and other information
你的下一台电脑何必是电脑,探索不一样的远程操作
RHCSA3
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
Compile kernel modules separately
Didi open source Delta: AI developers can easily train natural language models
JDBC -- extract JDBC tool classes
Preliminary exploration of basic knowledge of MySQL
Annotation problem and hidden Markov model
JSON parsing error special character processing (really speechless... Troubleshooting for a long time)
Kotlin变量
Wechat enterprise payment to change access, open quickly
Principle of universal gbase high availability synchronization tool in Nanjing University
Notes for preparation of information system project manager --- information knowledge
Taobao order amount check error, avoid capital loss API
A deep long article on the simplification and acceleration of join operation
RHCSA7
RHCSA2