首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-09-16 
表数据追加插入SQL有表A和表B的表结构完全一致,A,B中有部分数据相同,如何把A中的数据追加插入到B表中?即,

表数据追加插入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) 

热点排行