当前位置:网站首页>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 !
边栏推荐
- qt creater断点调试程序详解
- 当代人的水焦虑:好水究竟在哪里?
- SQL Server learning notes
- Bugku's Ah Da
- MySQL----函数
- JS knowledge points-01
- Common interview questions about swoole
- What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
- Bugku's Eval
- Redis distributed lock principle and its implementation with PHP (1)
猜你喜欢
I spring and autumn blasting-2
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
ionic cordova项目修改插件
F. Min cost string problem solving Report
Bugku's eyes are not real
当代人的水焦虑:好水究竟在哪里?
No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
Creation and use of thymeleaf template
Mysql---- function
P6183 [USACO10MAR] The Rock Game S
随机推荐
P6183 [USACO10MAR] The Rock Game S
12 MySQL interview questions that you must chew through to enter Alibaba
Common interview questions about swoole
Can I pass the PMP Exam in 20 days?
MySQL 巨坑:update 更新慎用影响行数做判断!!!
How to introduce devsecops into enterprises?
Bugku's Ping
Redis' transaction mechanism
MySQL表字段调整
可转债打新在哪里操作开户是更安全可靠的呢
Cartoon: programmers don't repair computers!
Bugku's eyes are not real
Huiyuan, 30, is going to have a new owner
Transfer the idea of "Zhongtai" to the code
sql server char nchar varchar和nvarchar的区别
Dark horse programmer - software testing -10 stage 2-linux and database -44-57 why learn database, description of database classification relational database, description of Navicat operation data, de
Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
sql server学习笔记
一文搞定vscode编写go程序