当前位置:网站首页>Interviewer: have you made a judgment on the number of rows affected by your update?
Interviewer: have you made a judgment on the number of rows affected by your update?
2022-07-21 22:30:00 【Technical Trivia】
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 )
// 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 . in addition , newest MySQL The interview questions are sorted out , You can Java Interview library applet online brush questions .
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 !
边栏推荐
- Learn multithreading, process and development board together
- 深入剖析多重背包问题(下篇)
- 你觉得分库分表真的适合你的系统吗?聊聊分库分表和NewSQL如何选择
- 使用 KubeKey 搭建 Kubernetes/KubeSphere 环境的“心路(累)历程“
- Further learning of 02 selenium (control browser window +)
- 面试官:你的update 更新影响行数做判断了吗?
- Typescript学习笔记
- . Net memory leakage causes and Solutions
- 02-selenium的进一步学习(控制浏览器窗口+)
- 手把手教你如何使用Charles抓包
猜你喜欢
Jmeter进阶之性能测试响应结果保存到本地
22张图带你深入剖析前缀、中缀、后缀表达式以及表达式求值
[ALM] Introduction to the demand management solution of polaron ALM
Task and Await: Consuming Awaitable Methods
Polarion uses code to manage requirements and test documents
The top three suddenly changed? Unveil the latest ranking of programming languages in July
The robotframework (ride) keyword cannot be used or the keyword is black
The 22 pictures show you in-depth analysis of prefix, infix, suffix expressions and expression evaluation
Google Chrome -- xpathhelper installation
Teach you how to use yolov4 training and testing data set on the server (nanny level)
随机推荐
10 classic C language interview basic algorithms
.Net内存泄露原因及解决办法
JMeter中如何实现接口之间的关联?
Learn multithreading, process and development board together
Healthcare technology innovators use polarion software to reduce test creation time by up to 75%
. Net memory leakage causes and Solutions
About the understanding of automated testing: purpose and essence! (must see for beginners)
Typescript generics
DevStream 成为 CNCF Sandbox 项目啦!- 锣鼓喧天、鞭炮齐鸣、红旗招展、忘词了。
Does NMN product really have its effect? What effect does it have after taking NMN for several months
深入剖析斐波拉契数列
Basic process of APP testing and key points of APP testing
Do you know how to build data-driven, keyword driven and hybrid selenium framework
Polarion uses code to manage requirements and test documents
为什么不用定时任务实现关闭订单?
The top three suddenly changed? Unveil the latest ranking of programming languages in July
手把手教你在服务器上用YOLOv4训练和测试数据集(保姆级)
YOLOv4(darknet版)后处理:显示置信度、保存检测框的内容到本地
一起学习多线程、进程、开发板
参与开源社区还有证书拿?