mysql insert update語句
執行這條語句,會幫你自動判斷數據庫中是否有與你要插入的記錄重復主鍵,
有則更新,沒有就插入
格式如:insert into tablename(字段1,字段2) select * from
(select ? 字段1,? 字段2,.... from dual) as b on duplicate key update字段1=b.字段1,....
www.2cto.com
例子:insert into trtb_dim_top_cats
(cid,parent_cid,name,is_parent,status,sort_order,lev)
select * from (select ? cid,? parent_cid,? name,? is_parent,? status,? sort_order,?
lev from dual)
as b on duplicate key update
cid=b.cid,parent_cid=b.parent_cid,name=b.name,is_parent=b.is_parent,status=b.status,
sort_order=b.sort_order,lev=b.lev