当前位置:网站首页>MySQL insert \ pre update + judgment condition
MySQL insert \ pre update + judgment condition
2022-07-01 01:50:00 【Changchun bully】
1、mysql Operation to determine whether data exists before inserting
INSERT INTO table(field1, field2, fieldn) SELECT 'field1',
'field2', 'fieldn' FROM DUAL WHERE NOT EXISTS(SELECT field FROM
table WHERE field = ?)
2、 Insert if it doesn't exist , If it exists, it will be updated
If the inserted data will cause UNIQUE Index or PRIMARY KEY conflict / repeat , execute UPDATE sentence
INSERT INTO `student`(`name`, `age`) VALUES('Jack', 19)
ON DUPLICATE KEY
UPDATE `age`=19;
-- If will happen conflict, the update statement is executed 2 row(s) affected
3、 If the inserted data will cause UNIQUE Index or PRIMARY KEY conflict / repeat , Delete the old data first and then insert the latest data
REPLACE INTO `student`(`name`, `age`) VALUES('Jack', 18);4、 Avoid repeated insertion
keyword / sentence :insert ignore into, If the inserted data will cause UNIQUE Index or PRIMARY KEY conflict / repeat , Ignore this operation / Don't insert data
INSERT IGNORE INTO `student`(`name`, `age`) VALUES('Jack', 18);
-- 0 row(s) affected边栏推荐
猜你喜欢

软件开发中的上游和下游
![[无线通信基础-15]:图解移动通信技术与应用发展-3- 数字通信2G GSM、CDMA、3G WDCMA/CDMA200/TD-SCDMA、4G LTE、5G NR概述](/img/22/1efa444220131359b06005f597c9db.png)
[无线通信基础-15]:图解移动通信技术与应用发展-3- 数字通信2G GSM、CDMA、3G WDCMA/CDMA200/TD-SCDMA、4G LTE、5G NR概述

测试必备工具—Postman实战教程

哪有什么未来可期,不过是打工人临死前最后的幻想罢了

数据探索电商平台用户行为流失分析

3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全

计算特殊奖金

For the sustainable development of software testing, we must learn to knock code?

45 year old programmer tells you: why do programmers want to change jobs? It's too true

Log logrus third party library usage
随机推荐
Last day of the second quarter
org.redisson.client.RedisResponseTimeoutException: Redis server response timeout (3000 ms)错误解决
[simulation] 922 Sort Array By Parity II
3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全
【JS】【掘金】获取关注了里不在关注者里的人
opencv -- 笔记
【Proteus仿真】Arduino UNO +74C922键盘解码驱动4X4矩阵键盘
【JS给元素添加属性:setAttribute;classList.remove;classList.add;】
测试必备工具—Postman实战教程
Draw some interesting figures with flutter's canvas
[content of content type request header]
Mathematical knowledge: finding combinatorial number III - finding combinatorial number
对象与对象变量
php将二维数组元素转为键值对
测试必备工具-Postman实战教程
迪赛智慧数——其他图表(平行坐标图):2021年应届专业就业情况
亲测有效,快速创建JMeter桌面快捷方式
System. Csrebot for commandline
数据探索电商平台用户行为流失分析
Microbial safety and health, what is biological treatment?