SQL Table compare

declare @A table (ID int , Name nvarchar(max))
declare @B table (ID int , Name nvarchar(max))

insert into @A values(1,’zzzzzz1′)
insert into @A values(2,’zzzzzz111′)
insert into @A values(3,’zzzzzz3′)
insert into @A values(4,’zzzzzz4′)

insert into @B values(1,’zzzzzz1′)
insert into @B values(2,’zzzzzz2′)
insert into @B values(3,’zzzzzz3′)

 

select ‘ Rows in A that are not in B’
select * from @A
EXCEPT
select * from @B

select ‘ Rows in B that are not in A’
select * from @B
EXCEPT
select * from  @A

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s