用sql语句比较两个表的数量和数据是否一致。很急很急,求大神,谢谢sql数据

解决方案 »

  1.   

    你想比较整个表,不是其中一两个字段?如:
    比较两个字段,a表存在而b表不存在的数据
    select a.*
    from a
    where not exists(select 1 from b where a.col1=b.col1 and a.col2=b.col2)
      

  2.   

    下面是b表存在而a表不存的数据
    select *
    from b
    where not exists(select 1 from a where a.col1=b.col1 and a.col2=b.col2)如果两条语句查询都为空,说明两表数据一样,只要有数据出来,就说明两表数据有不一样
      

  3.   

    简单select * from table1
    except 
    select * from table2
      

  4.   

    如果是2个不同数据库的表,能比较么为何不能?除非两个数据库无法连通~
    select * from DB1.dbo.table1
    except 
    select * from DB2.dbo.table2or
    select * from Server1.DB1.dbo.table1
    except 
    select * from Server2.DB2.dbo.table2