当前位置:网站首页>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 !
边栏推荐
- 2021.12.16-2021.12.20 empty four hand transaction records
- SAP UI5 DynamicPage 控件介紹
- 国内市场上的BI软件,到底有啥区别
- Distributed cache architecture - cache avalanche & penetration & hit rate
- 在家庭智能照明中应用的测距传感芯片4530A
- SAP UI5 视图里的 OverflowToolbar 控件
- Taobao short videos are automatically released in batches without manual RPA open source
- stirring! 2022 open atom global open source summit registration is hot!
- Annotation problem and hidden Markov model
- Programming skills for optimizing program performance
猜你喜欢
Volatile instruction rearrangement and why instruction rearrangement is prohibited
从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
Transactions from December 29, 2021 to January 4, 2022
Transactions from December 27 to 28, 2021
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
SAP UI5 DynamicPage 控件介绍
Research: data security tools cannot resist blackmail software in 60% of cases
谈谈我写作生涯的画图技巧
《信息系统项目管理师》备考笔记---信息化知识
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
随机推荐
Common commands and basic operations of Apache Phoenix
What if wechat is mistakenly sealed? Explain the underlying logic of wechat seal in detail
Lepton 无损压缩原理及性能分析
Storage Basics
前几年外包干了四年,秋招感觉人生就这样了..
ActiveMQ installation and deployment simple configuration (personal test)
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
Kotlin变量
SAP self-development records user login logs and other information
Taobao short videos are automatically released in batches without manual RPA open source
10 minute fitness method reading notes (3/5)
自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
C alarm design
自然语言处理系列(一)入门概述
Super efficient! The secret of swagger Yapi
使用 jMeter 对 SAP Spartacus 进行并发性能测试
Reshape the power of multi cloud products with VMware innovation
Why is your next computer a computer? Explore different remote operations
NFT: how to make money with unique assets?
RHCAS6