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

怎么判断一个表内的数据是否在另一个表内存在

2012-04-13 
如何判断一个表内的数据是否在另一个表内存在我现在有一个数据表A和数据表B,现在我想判断数据表B内的数据

如何判断一个表内的数据是否在另一个表内存在
我现在有一个数据表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)

热点排行