当前位置:网站首页>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 !
边栏推荐
- UNIX socket advanced learning diary - advanced i/o functions
- Introduction to the principle of DNS
- Annotation problem and hidden Markov model
- 2021-12-21 transaction record
- 开发者,云原生数据库是未来吗?
- Introduction to relational model theory
- SAP UI5 FlexibleColumnLayout 控件介绍
- CVPR 2022 | 基于稀疏 Transformer 的单步三维目标识别器
- Distributed cache architecture - cache avalanche & penetration & hit rate
- RHCSA3
猜你喜欢

滴滴开源DELTA:AI开发者可轻松训练自然语言模型

初识Linkerd项目

Transactions from December 27 to 28, 2021

MySQL 巨坑:update 更新慎用影响行数做判断!!!

What if wechat is mistakenly sealed? Explain the underlying logic of wechat seal in detail

Transactions from December 29, 2021 to January 4, 2022

Annotation problem and hidden Markov model

石臻臻的2021总结和2022展望 | 文末彩蛋

Taobao product details API | get baby SKU, main map, evaluation and other API interfaces

研究:数据安全工具在 60% 的情况下无法抵御勒索软件
随机推荐
超高效!Swagger-Yapi的秘密
RHCSA5
10 minute fitness method reading notes (1/5)
Taobao order interface | order flag remarks, may be the most stable and easy-to-use interface
Pytoch counts the number of the same elements in the tensor
2021-12-22 transaction record
Database connection pool & jdbctemplate
How can non-technical departments participate in Devops?
Simply take stock reading notes (2/8)
How can labels/legends be added for all chart types in chart. js (chartjs.org)?
Notes for preparation of information system project manager --- information knowledge
Full text search of MySQL
Taobao short videos are automatically released in batches without manual RPA open source
实战模拟│JWT 登录认证
Simply take stock reading notes (3/8)
以VMware创新之道,重塑多云产品力
155. 最小栈
stm32和电机开发(从架构图到文档编写)
SAP self-development records user login logs and other information
滴滴开源DELTA:AI开发者可轻松训练自然语言模型