当前位置: 代码迷 >> Sql Server >> 表数据追加插入SQL解决方法
  详细解决方案

表数据追加插入SQL解决方法

热度:7   发布时间:2016-04-27 11:14:46.0
表数据追加插入SQL
有表A和表B的表结构完全一致,A,B中有部分数据相同,如何把A中的数据追加插入到B表中?即,如果A表中的数据x在B表存在,不插入,如果不存在则插入B表。
 

------解决方案--------------------
SQL code
trucate table binsert into bselect * fro a
------解决方案--------------------
SQL code
insert b select a.* from a left join b on a.key=b.key where b.key is null
------解决方案--------------------
SQL code
insert B select * from A where not exists(select 1 from B where a.x=b.x)
  相关解决方案