select * from A left join B 
 ON A.col1 = B.col1 and A.col2=B.col2 and A、B的其它字段 WHERE B.col1 is null
union
select * from B left join A 
 ON A.col1 = B.col1 and A.col2=B.col2 and A、B的其它字段 where A.col1 is null如过上面查询出来有记录,那就说明两个表不同
select * from A left join B 
 ON A.col1 = B.col1 and A.col2=B.col2 and A、B的其它字段 WHERE B.col1 is null
上一句是A表有的记录,B表没有select * from B left join A 
 ON A.col1 = B.col1 and A.col2=B.col2 and A、B的其它字段 where A.col1 is null
这一句就是B表有的记录,A表没有

解决方案 »

  1.   

    SELECT COUNT(*)
    FROM Table1 As t1 , Table2 As t2
    WHERE t1.Filed1 <> t2.Field1 AND t1.Field2 <> t2.Field2 AND ……不过字段很多时也够烦的,而且效率也不高。
    继续关注
      

  2.   

    或者这样:
    SELECT TOP 1 *
    FROM Table1 As t1 , Table2 As t2
    WHERE t1.Filed1 <> t2.Field1 AND t1.Field2 <> t2.Field2 AND ……
    当记录集打开时为空,则完全相同,否则不完全相同。我想这样查询速度还快一些。
      

  3.   

    select * from A
    minus
    select * from b