当前位置:网站首页>mysql uses on duplicate key update to update data in batches
mysql uses on duplicate key update to update data in batches
2022-07-31 04:53:00 【jiey0407】
Create Test—book Chart of Accounts
CREATE TABLE `book` (`id` int NOT NULL AUTO_INCREMENT,`unique_code` varchar(30) NOT NULL,`book_name` varchar(20) DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `unique_code` (`unique_code`) USING BTREE COMMENT 'book unique_code') ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
The premise requires that there is an index in the table: as follows unique_code is the index
Requirements:Data needs to be imported into the book table.When there is account data in the book table, update the data value, otherwise insert inserts a new record.
Previous practice: circularly select whether the booke record in the table exists, use update if it exists; use insert if it does not exist.
Disadvantages of practice: Each record needs to be operated twice (select, update/insert)
Optimization: use the insert statement with on duplicate key update.
Practice Note: For example, for the above requirements, you need to use book table**** uniqueunique_code index
I. Execute the following command
insert into book(unique_code,book_name) values ('zs-001','Chinese') on duplicate key update book_name='math';
2. Execute the command in step 1 again and you will find that the value of book_name has changed
Simple and easy to understand~~
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
- [debug highlights] Expected input batch_size (1) to match target batch_size (0)
- XSS shooting range (3) prompt to win
- Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world
- WeChat applet uses cloud functions to update and add cloud database nested array elements
- Minesweeper game - C language
- MATLAB/Simulink & & STM32CubeMX tool chain completes model-based design development (MBD) (three)
- ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)
- Hand in hand to realize the picture preview plug-in (3)
- Create componentized development based on ILRuntime hot update
猜你喜欢
Unity URP渲染管线摄像机核心机制剖析
Reinforcement learning: from entry to pit to shit
mysql数据库安装(详细)
DVWA安装教程(懂你的不懂·详细)
Hand in hand to realize the picture preview plug-in (3)
开源社区三十年 | 2022开放原子全球开源峰会开源社区三十年专题活动圆满召开
1. 获取数据-requests.get()
[C language] Detailed explanation of operators
STM32HAL library modifies Hal_Delay to us-level delay
【云原生】DevOps(五):集成Harbor
随机推荐
Three oj questions on leetcode
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)
SQL row-column conversion
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
[Linear Neural Network] softmax regression
ERP Production Operation Control Kingdee
PCL 计算点云坐标最值及其索引
XSS shooting range (3) prompt to win
Fusion Cloud Native, Empowering New Milestones | 2022 Open Atom Global Open Source Summit Cloud Native Sub-Forum Successfully Held
【wpf】wpf中的那些模板之深度解析
On Governance and Innovation | 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum was successfully held
three.js make 3D photo album
[C language] Detailed explanation of operators
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
两个地址池r2负责管地址池r1负责管dhcp中继
Explanation of
Minesweeper game - C language
centos7安装mysql5.7
DVWA安装教程(懂你的不懂·详细)
益智类游戏关卡设计:逆推法--巧解益智类游戏关卡设计