当前位置:网站首页>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
边栏推荐
- 益智类游戏关卡设计:逆推法--巧解益智类游戏关卡设计
- MySQL优化:从十几秒优化到三百毫秒
- 30 Years of Open Source Community | 2022 Open Atom Global Open Source Summit 30 Years of Open Source Community Special Event Held Successfully
- Mysql应用安装后找不到my.ini文件
- 【ORACLE Explain 详解】
- 从零开始,一镜到底,纯净系统搭建除草机(Grasscutter)
- EasyExcel的简单读取操作
- 12个MySQL慢查询的原因分析
- ENSP,划分VLAN、静态路由,三层交换机综合配置
- The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
猜你喜欢

ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your

从零开始,一镜到底,纯净系统搭建除草机(Grasscutter)

Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法

ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)Solution
![Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]](/img/7c/c9ab32bbf43b933e5f84f0d142f7bd.jpg)
Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]

城市内涝及桥洞隧道积水在线监测系统

Unity手机游戏性能优化系列:针对CPU端的性能调优

Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world

MySQL数据库必会的增删查改操作(CRUD)

prompt.ml/15中<svg>标签使用解释
随机推荐
Unity URP渲染管线摄像机核心机制剖析
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
CentOS7 install MySQL graphic detailed tutorial
Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
[Cloud Native] DevOps (5): Integrating Harbor
开源社区三十年 | 2022开放原子全球开源峰会开源社区三十年专题活动圆满召开
Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
Minio上传文件ssl证书不受信任
mysql数据库安装(详细)
聚变云原生,赋能新里程 | 2022开放原子全球开源峰会云原生分论坛圆满召开
SOLVED: After accidentally uninstalling pip (two ways to manually install pip)
HCIP第十天_BGP路由汇总实验
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
【debug锦集】Expected input batch_size (1) to match target batch_size (0)
Heavyweight | The Open Atomic School Source Line activity was officially launched
Minesweeper game (written in c language)
重磅 | 开放原子校源行活动正式启动
开放原子开源基金会秘书长孙文龙 | 凝心聚力,共拓开源