日期:2014-05-18  浏览次数:20527 次

如何判断一个表内的数据是否在另一个表内存在
我现在有一个数据表A和数据表B,现在我想判断数据表B内的数据在数据表A内是否已经存在,将不存在的数据从B导插入到A中,请问这个该怎么操作啊?
可以用VS写也可以用Tsql写

------解决方案--------------------
insert into A
select * from B
where not exists(select 1 from A where A.主键=B.主键)
------解决方案--------------------
insert into a
select * from b where id not in (select id from a)
------解决方案--------------------
insert into b select * from a where id not in (select id from b)