当前位置: 代码迷 >> Sql Server >> SQL Server怎么做两个数据库表的对比查询
  详细解决方案

SQL Server怎么做两个数据库表的对比查询

热度:42   发布时间:2016-04-27 12:40:03.0
SQL Server如何做两个数据库表的对比查询
ASP.NET如何做同一数据库中两个结构相同数据库表(A表、B表)的数据对比


最好能查询出A表中有B表中没有的,B表中有A表中没有的,
也就是两个表中不同的数据


做到一目了然的对比效果,请求高手指教

------解决方案--------------------
select * from a
where not exists(select 1 from B where a.col=b.col)
union all
select * from B
where not exists(select 1 from A where a.col=b.col)
------解决方案--------------------
A表中有B表中没有的:
select * form a
except
select * from b

B表中有A表中没有的:
select * from b
except
select * from a
  相关解决方案