on duplicate key update (存在即更新)
在项目使用insert增加中,如果主键或唯一索引在现有表中已经存在,则会执行更新操作,实现方式就是在SQL语句insert中添加 on duplicate key update ,表示存在就执行 update语句,不存在执行 insert语句
insert into user(id,name,age)
values(
on DUPLICATE key update
id = values(id),
name = values(name),
age = values(age)