当前位置:网站首页>MySql中IGNORE、ON DUPLICATE KEY UPDATE、DELAYED
MySql中IGNORE、ON DUPLICATE KEY UPDATE、DELAYED
2022-07-15 11:24:00 【Amazing_deron】
mysql插入语句中,如果指定了IGNORE,则对于有重复关键字的行,只使用第一行,其它有冲突的行被删除。
示例:
insert ignore into tb(...) value(...)
这样不用校验是否存在了,有则忽略,无则添加。
如果不指定ignore时,有唯一冲突时会报错。
mysql插入语句中如果指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则执行旧行UPDATE。
例如,如果列a被定义为UNIQUE,并且包含值1,则以下两个语句具有相同的效果:
INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;
UPDATE table SET c=c+1 WHERE a=1;
您可以在UPDATE子句中使用VALUES(col_name)函数从INSERT...UPDATE语句的INSERT部分引用列值。
示例:
INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6)
ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);
本语句与以下两个语句作用相同:
INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=3;
INSERT INTO table (a,b,c) VALUES (4,5,6) ON DUPLICATE KEY UPDATE c=9;
DELAYED调节符应用于INSERT和REPLACE语句。当DELAYED插入操作到达的时候,
服务器把数据行放入一个队列中,并立即给客户端返回一个状态信息,这样客户
端就可以在数据表被真正地插入记录之前继续进行操作了。
示例:
insert DELAYED into tb(...) value(...)
几点要注意事项:
INSERT DELAYED应该仅用于指定值清单的INSERT语句。
服务器忽略用于INSERT DELAYED...SELECT语句的DELAYED。
服务器忽略用于INSERT DELAYED...ON DUPLICATE UPDATE语句的DELAYED。
总结:
DELAYED做为快速插入,并不是很关心失效性,提高插入性能。
IGNORE只关注主键对应记录是不存在,无则添加,有则忽略。
ON DUPLICATE KEY UPDATE 在添加时操作,关注非主键列,注意与ignore的区别。有则更新指定列,无则添加。
边栏推荐
- eth入门之节点与客户端
- 如何选择合适的自动化测试工具?
- Tiktok launched "group purchase and distribution" to explore a new model of takeout
- Cf1422c bargain (DP + thinking + Mathematics)
- Quick start to 3dsmax development
- Latex mathematical formula
- Learn FPGA from the bottom structure --- MMCM and PLL
- 第8章 委托、lambda表达式和事件
- diffusion model
- Inner class
猜你喜欢

上海港口航运人工智能集装箱人工智能独角兽中集飞瞳,港航人工智能产品市场占有率领先,带动港航人工智能集装箱人工智能全产业链发展

一图看懂:国企数字化转型4个方向3个战略

Aof of redis persistence

开源实时数仓 Apache Doris 毕业了,未来如何走得更远?

2022全球开发者薪资PK:中国排在第19名,使用Go语言最赚钱

实验1.SQL Server的安全机制

堆排序

What are the problems we need to pay attention to in setting the standard of Baidu search basic information?

How can Volvo be confident to maintain "zero casualties" in traffic safety in the era of electrification?

The type initializer of "opencvsharp.mat" threw an exception
随机推荐
Pat brush questions
实验2.售后服务管理系统数据建模
What is the principle of tree shaking?
堆排序
fast Fourier transform
实验3.选课系统
【福利活动】给你的代码叠个 Buff!点击“茶”收好礼
想要白嫖正则是吧?这一次给你个够!
Experiment 3 Course selection system
diffusion model
Educational codeforces round 112 (rated for Div. 2) d. say no to palindromes (prefix and + thinking)
How to choose the appropriate automated testing tools?
Servlet api code example: server version confession wall
Golang problem summary
STM32 and Internet of things 02 network data sending and receiving
如何复活古人?#MetaHuman 让万年前的骨架重获肉身
Matlab summary
Experiment 1 Security mechanism of SQL Server
51 single chip microcomputer serial port baud rate (keep it and don't look everywhere)
#微信小程序# #uni-app# 实现提交表单或登录,需勾选同意协议,才可以进行下一步