create schema authorization sa create table #t1 ( i1 int , c1 char( 1 ) , vc1 varchar( 10 ) ) create table #t2 ( i2 int , c2 char( 1 ) , vc2 varchar( 10 ) ) go
insert into #t1 values( 1 , '1' , '1111' ); insert into #t1 values( 11 , 'a' , 'aaaa' ); insert into #t2 values( 1 , '1' , '1111' ); insert into #t2 values( 2 , '2' , '2222' ); go
select i1 , c1 , vc1 from ( select * , checksum( * ) as chksum1 from #t1 ) as t1 where not exists ( select * from ( select * , checksum( * ) as chksum2 from #t2 ) as t2 where chksum1 = chksum2 );
select i2 , c2 , vc2 from ( select * , checksum( * ) as chksum2 from #t2 ) as t2 where not exists ( select * from ( select * , checksum( * ) as chksum1 from #t1 ) as t1 where chksum1 = chksum2 )
select i1 , c1 , vc1 from ( select * , checksum( * ) as chksum1 from #t1 ) as t1 where exists ( select * from ( select * , checksum( * ) as chksum2 from #t2 ) as t2 where chksum1 = chksum2 ); go
alter table #t1 Add chksum as ( checksum( i1 , c1 , vc1 ) ); alter table #t2 Add chksum as ( checksum( i2 , c2 , vc2 ) ); go
select i1 , c1 , vc1 from #t1 as t1 where not exists ( select * from #t2 as t2 where t1.chksum = t2.chksum );
select i2 , c2 , vc2 from #t2 as t2 where not exists ( select * from #t1 as t1 where t1.chksum = t2.chksum )
select i1 , c1 , vc1 from #t1 as t1 where exists ( select * from #t2 as t2 where t1.chksum = t2.chksum ); go drop table #t2; drop table #t1; go |