mysql批量操做語句

一、.replace into 批量更新spa

   replace into t_student(id,dr) values (1,'2'),(2,'3'),...(x,'y');code

例子:class

    replace into t_student (`Id`,`Author`,`CreatedTime`,`UpdatedTime`) values (1,'王五','2016-12-12 12:20','2016-12-12 12:20'), (2,'張三','2016-12-12 12:20','2016-12-12 12:20');

二、insert into ...on duplicate key update批量更新
  insert into t_student(id,dr) values (1,'2'),(2,'3'),...(x,'y') on duplicate key update dr=values(dr);
date

  例子:im

 insert into t_student (`Id`,`Author`,`CreatedTime`,`UpdatedTime`) values (1,'張三','2017-12-12 12:20','2017-12-12 12:20'), (2,'王五','2017-12-12 12:20','2017-12-12 12:20') on duplicate key update Author=values(Author), CreatedTime=values(CreatedTime), UpdatedTime=values(UpdatedTime);

replace into  和 insert into on duplicate key update的不一樣在於:co

相關文章
相關標籤/搜索