当前位置:网站首页>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 15:29: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 !
边栏推荐
- Ctfshow web entry information collection
- 30岁汇源,要换新主人了
- JMeter performance test: serveragent resource monitoring
- Go language programming specification combing summary
- Your childhood happiness was contracted by it
- MySQL表字段调整
- 如何将 DevSecOps 引入企业?
- Maximum common subsequence
- Redis distributed lock principle and its implementation with PHP (2)
- ICML 2022 | explore the best architecture and training method of language model
猜你喜欢

CSRF, XSS science popularization and defense

Interpretation of Apache linkage parameters in computing middleware

Huiyuan, 30, is going to have a new owner

Database learning - Database Security

OSI 七层模型

Redis' transaction mechanism

First PR notes

Transfer the idea of "Zhongtai" to the code

Detailed explanation of C language branch statements
![P6183 [USACO10MAR] The Rock Game S](/img/f4/d8c8763c27385d759d117b515fbf0f.png)
P6183 [USACO10MAR] The Rock Game S
随机推荐
P1451 求细胞数量/1329:【例8.2】细胞
sql server学习笔记
Can I pass the PMP Exam in 20 days?
Leetcode: Shortest Word Distance II
Common MySQL interview questions
Can gbase 8A view the location of SQL statement history?
亿咖通科技通过ISO27001与ISO21434安全管理体系认证
Common MySQL interview questions (1) (written MySQL interview questions)
一文搞定vscode编写go程序
OSI seven layer model
The difference between abstract classes and interfaces in PHP (PHP interview theory question)
Fr exercise topic --- comprehensive question
qt creater断点调试程序详解
wyt 。。
Crud de MySQL
Array sorting num ranking merge in ascending order
The difference between SQL Server char nchar varchar and nvarchar
P1451 calculate the number of cells / 1329: [example 8.2] cells
Thymeleaf uses background custom tool classes to process text
Common interview questions about swoole