MySql_插入记录时,存在就更新(或不做任何动作),不存在就插入添加

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenbetter1996/article/details/82719131

方法:

insert into table_name(a, b, c) values(a1, b1, c1) on duplicate key update b=b1, c=c1;

 前提,a是唯一约束unique             

 1.如果 a1 != a,则插入这条语句(仅仅和具有唯一约束的a有关)

 2.如果a1 = a, 则保持这条记录的a字段不变,更新b,c字段。

猜你喜欢

转载自blog.csdn.net/chenbetter1996/article/details/82719131
今日推荐