当前位置:网站首页>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 !
边栏推荐
- Talk about your understanding of microservices (PHP interview theory question)
- Appium自动化测试基础 — APPium基础操作API(一)
- Misc Basic test method and knowledge points of CTF
- swiper. JS to achieve barrage effect
- lvgl 显示图片示例
- Can gbase 8A view the location of SQL statement history?
- JMeter performance test: serveragent resource monitoring
- Bugku's Ah Da
- Leetcode: Shortest Word Distance II
- Temporary cramming before DFS examination
猜你喜欢

D-snow halo solution

Transfer the idea of "Zhongtai" to the code

MySQL----函数

How to paste the contents copied by the computer into mobaxterm? How to copy and paste

Example of lvgl display picture

Reasons and solutions for redis cache penetration and cache avalanche

"Sequelae" of the withdrawal of community group purchase from the city

亿咖通科技通过ISO27001与ISO21434安全管理体系认证

Value series solution report

Advanced level of static and extern
随机推荐
ICML 2022 | 探索语言模型的最佳架构和训练方法
数据库学习——数据库安全性
Can gbase 8A view the location of SQL statement history?
Fr exercise topic - simple question
Ctfshow web entry explosion
Hongmeng system -- Analysis from the perspective of business
【简记】解决IDE golang 代码飘红报错
华为哈勃化身硬科技IPO收割机
社区团购撤城“后遗症”
Creation and use of thymeleaf template
Brief introduction of machine learning framework
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
Huiyuan, 30, is going to have a new owner
queryRunner. Query method
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
CODING DevSecOps 助力金融企业跑出数字加速度
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
How to introduce devsecops into enterprises?
ionic cordova项目修改插件
PHP high concurrency and large traffic solution (PHP interview theory question)