当前位置:网站首页>Two methods of covering duplicate records in tables in MySQL
Two methods of covering duplicate records in tables in MySQL
2022-07-28 06:01:00 【Programmer awei】
replace into The way
Prerequisite
There must be a primary key or unique index in the table .
principle
Find data with the same primary key according to the primary key or unique index , Then delete the original data , Add new data .
If there is no same primary key or unique index in the table , It's equivalent to insert into.
Use cases
# topic、partition、groupid It's the primary key
replace into t_offset (`topic`, `partition`, `groupid`, `offset`) values(?,?,?,?)")ON DUPLICATE KEY UPDATE The way
Prerequisite
There must be a primary key or unique index in the table .
principle
Find data with the same primary key according to the primary key or unique index , And then execute update update operation .
If there is no same primary key or unique index in the table , It's equivalent to insert into.
Use cases
# userid It's the primary key
insert into black_list(userid) value (?)
on DUPLICATE KEY
UPDATE userid = ?边栏推荐
猜你喜欢
随机推荐
微信小程序手机号正则校验规则
Sales notice: on July 22, the "great heat" will be sold, and the [traditional national wind 24 solar terms] will be sold in summer.
CMD and NPM basic commands
(php毕业设计)基于php校园网络报修管理系统获取
Chapter IX sub query (key)
flex弹性盒子项目属性
trino函数随记
(php毕业设计)基于thinkphp5校园新闻发布管理系统获取
raise RuntimeError(‘DataLoader worker (pid(s) {}) exited unexpectedly‘.format(pids_str))RuntimeErro
mysql分页出现问题
50 MySQL exercises + Answers
Acquisition of student status management system based on PHP (PHP graduation design)
【五】redis主从同步与Redis Sentinel(哨兵)
(php毕业设计)基于php学生作业提交管理系统获取
发售预告:7月22日“大暑”发售,【传统国风廿四节气】夏季发售完毕。
(php毕业设计)基于php在线旅游网站管理系统获取
MySQL练习题50道+答案
基于php心理健康服务系统获取(php毕业设计)
排序与分页,多表查询课后练习
At the moment of the epidemic, online and offline travelers are trapped. Can the digital collection be released?









