Beyondrelational

Wednesday, June 9, 2010

How to data compare two tables using EXCEPT?

Execute the following script in Query Editor to demonstrate the data compare of two identical tables using the EXCEPT operator. If both EXCEPT queries return empty result sets, the two tables are identical.



select * into dbo.ProductInventory
from AdventureWorks.Production.ProductInventory
go


insert into dbo.ProductInventory  
values ('10','1','A','1','408','47A24246-6C43-48EB-968F-025738A8A410','2004-09-08 00:00:00.000')
go


select * from dbo.ProductInventory
except
select * from AdventureWorks.Production.ProductInventory
go

select * from AdventureWorks.Production.ProductInventory
except
select * from dbo.ProductInventory
go


drop table dbo.ProductInventory
go


No comments:

Post a Comment