当前位置:网站首页>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
边栏推荐
- 【图像增强】基于人工多重曝光融合AMEF实现图像去雾附matlab代码
- 【特征提取】基于稀疏PCA实现目标识别信息特征选择附matlab源码
- ZRaQnHYDAe
- ES字符串类型(Text vs keyword)的选择
- How to transfer database data to check box
- NumPy学习挑战第五关-创建数组
- PyTorch搭建CNN-LSTM混合模型实现多变量多步长时间序列预测(负荷预测)
- Thymeleaf中使用二维数组[[]]报错:Could not parse as expression
- I caught a 10-year-old Alibaba test developer in the company. After chatting with him, I realized everything
- NumPy学习挑战第一关-NumPy的下载与安装
猜你喜欢

大厂面试TCP协议经典十五连问!22张图让你彻底弄明白

安装homebrew报错汇总
![[yolov4] matlab simulation of network target detection based on yolov4 deep learning](/img/f9/31aba8f8bc04ccb16486dc87712ef6.png)
[yolov4] matlab simulation of network target detection based on yolov4 deep learning

Easyar use of unity

Paths with a certain value in a binary tree (1) (2) (3) (Sword finger offer)
![[004] [stm32] MDK project configuration and commissioning](/img/a8/9817cdbbce557a92739de494490706.jpg)
[004] [stm32] MDK project configuration and commissioning
![[cellular automata] Based on cellular automata, realize the traffic flow problem of expressway toll station, with matlab code](/img/6c/488be82a720635333eea90adcc388f.png)
[cellular automata] Based on cellular automata, realize the traffic flow problem of expressway toll station, with matlab code

One chip realizes functions such as spray 𞓜 ws2812 drive | key touch | LED display | voice broadcast chip and simplifies the design of humidifier products

QTreeWidget And QTableWidget

Mysql操作数据库
随机推荐
同花顺究竟如何开户,网上开户是否安全么?
NumPy学习挑战第一关-NumPy的下载与安装
Crosslinked porphyrin based polyimide ppbpi-2, ppbpi-1-cr and ppbpi-2-cr; Porous porphyrin based hyperbranched polyimide (ppbpi-1, ppbpi-2) supplied by Qiyue
I caught a 10-year-old Alibaba test developer in the company. After chatting with him, I realized everything
SQL query statement
基于sanic的服务使用celery完成动态修改定时任务
解决dialog 底部透明的问题
On a classical problem
Analyse d'un problème classique
淺析一道經典題
Show statement usage supplement
SQL中空值的判断
安装homebrew报错汇总
How to open an account in flush? Is it safe to open an account online?
Professional course - Code question record
【图像分割】基于最大主曲率实现视网膜眼底图像中的血管提取附matlab代码
缓存使用
item2安装配置及环境失效问题解决
Fmt Must the result of println (true) be true?
What is deadlock