Mysql插入重复处理

1.insert ignore into

重复忽略掉

1
insert ignore into test_user values(1,"张三",2)

2.on duplicate key update

唯一约束重复更新

1
insert into test_user values(1,"张三",2) on duplicate key update age = 3

3.replace into

无脑替换插入

1
replace into test_user values(2,"张三",2)

4.insert if not exists

配合where条件,不存在则插入

1
insert into test_user(id,name,age) select 4,"张三",2 from test_user where not EXISTS ( select id from test_user where id = 4) limit 1

Mysql插入重复处理
https://kanchai.club/2023/01/11/Mysql插入重复处理/
作者
625
发布于
2023年1月11日
许可协议