当前位置:网站首页>The difference between insert ignore and insert into
The difference between insert ignore and insert into
2022-06-26 07:07:00 【Talk to me】
INSERT IGNORE And INSERT INTO The difference is that INSERT IGNORE Will ignore the database already exists The data of , If there is no data in the database , Just insert new data , If you have data, skip this data . In this way, you can keep the existing data in the database , To insert data in the gap .
eg: insert ignore into table(name) select name from table2
mysql There are three kinds of statements to insert data :
insert into Means insert data , The database checks the primary key (PrimaryKey), If there is a repetition, an error will be reported ;
replace into Indicates insert replacement data , What is in the demand table PrimaryKey, perhaps unique Index words , If the database already has data , Replace with new data , If there's no data effect, it's the same as insert into equally ;
REPLACE Statement will return a number , To indicate the number of rows affected . This number is the sum of the number of rows deleted and inserted . If for a single line REPLACE The number is 1, Then a line is inserted , At the same time, no lines have been deleted . If the number is greater than 1, Before the new line is inserted , One or more old lines have been deleted . If the table contains multiple unique indexes , And the new row copies the values of different old rows in different unique indexes , It is possible that a single line replaces multiple old lines .
insert ignore Express , If the same record already exists in , Ignore the current new data ;
The difference is explained by the code below , as follows :
create table testtb(
id int not null primary key,
name varchar(50),
age int
);
insert into testtb(id,name,age)values(1,"bb",13);
select * from testtb;
insert ignore into testtb(id,name,age)values(1,"aa",13);
select * from testtb;// Is still 1,“bb”,13, because id It's the primary key , Duplicate primary key but used ignore The error is ignored
replace into testtb(id,name,age)values(1,"aa",12);
select * from testtb; // The data becomes 1,"aa",12
边栏推荐
- ES cluster_block_exception read_only_allow_delete问题
- Cocoscreator plays spine animation
- Development trends and prospects of acrylamide crystallization market in the world and China 2022-2027
- 【图像分割】基于最大主曲率实现视网膜眼底图像中的血管提取附matlab代码
- 13. Mismatch simulation of power synthesis for ads usage recording
- web入门之 Promise API
- 【图像融合】基于梯度能量、局部能量、 PCA三种融合规则实现MRI-CT图像融合附matlab代码
- QTreeWidget And QTableWidget
- 解决dialog 底部透明的问题
- Tetra - (4-pyridyl) porphyrin tpyp and metal complexes zntpyp/fetpyp/mntpyp/cutpyp/nitpyp/cotpyp/ptpyp/pdtpyp/cdtpyp (supplied by Qiyue porphyrin)
猜你喜欢

3D porphyrin MOF (mof-p5) / 3D porphyrin MOF (mof-p4) / 2D cobalt porphyrin MOF (ppf-1-co) / 2D porphyrin COF (POR COF) / supplied by Qiyue

【元胞自动机】基于元胞自动机实现高速公路收费站交通流问题附matlab代码

安装homebrew报错汇总

Numpy learning challenge level 4 - numpy array attribute

I caught a 10-year-old Alibaba test developer in the company. After chatting with him, I realized everything

缓存使用

13. Mismatch simulation of power synthesis for ads usage recording

What is data mining?

LabVIEW Arduino tcp/ip remote smart home system (project part-5)

If you meet a female driver who drives didi as an amateur, you can earn 500 yuan a day!
随机推荐
Numpy learning challenge level 4 - numpy array attribute
Excel中Unicode如何转换为汉字
QPS
MySQL 'replace into' 的坑 自增id,备机会有问题
Alkynyl crosslinked porphyrin based polyimide materials (ppbpi-h-cr, ppbpi Mn cr.ppbpi Fe Cr); Metalloporphyrin based polyimide (ppbpi Mn, ppbpi FE) supplied by Qiyue
[path planning] robot path planning based on improved artificial potential field with matlab code
unity之EasyAR使用
SQL
China peek market outlook and future strategic planning proposal report 2022-2027
Market scale forecast and investment risk forecast report of China's securities operating institutions 2022-2027
Shengshi Haotong enterprise wechat sector creates a digital ecological community
[feature extraction] feature selection of target recognition information based on sparse PCA with Matlab source code
【图像融合】基于梯度能量、局部能量、 PCA三种融合规则实现MRI-CT图像融合附matlab代码
How to publish function computing (FC) through cloud effect
一芯实现喷雾|WS2812驱动|按键触摸|LED显示|语音播报芯片等功能,简化加湿器产品设计
面试被问Redis主从复制不会答?这13张图让你彻底弄明白
ES字符串类型(Text vs keyword)的选择
Turris omnia: an open source router technology favored by hackers
【图像融合】基于耦合特征学习的多模式医学图像融合附matlab代码
MATLAB线性规划模型学习笔记