C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » SQL »

Comparing two tables Rows


Posted Date: 29 Oct 2009    Resource Type: Code Snippets    Category: SQL
Author: MelchiorMember Level: Gold    
Rating: 1 out of 5Points: 6



Comparing two tables Rows


In my project, I need to identify the data difference between two tables.Before that I want to give some more information about that requirement. I have two databases with different columns in the base table. By using the base table, we will create the remaining tables. If the columns are different in that base table, then entire database will be very complex for data migration.So we need to check that base table data before the migration.


Let’s consider the Customer_2000 and sales_2005 database and tblCustomerDetails and tblCustomerPersonDetails are base tables in the respective database. We have some unique fields [ID],[Name] and Location. By using those fields, we should identify the difference between the two tables.

Following query will give the required output as per my requirement:

SELECT MIN(TableName) as TableName, [ID],[Name], Location
FROM
(
SELECT 'Customer_2000.tblCustomerDetails' AS TableName, a.CustomerID,a.CustomerName, a.Location
FROM [EMS4_V7_HMI_Export].[dbo].[SK_APC_PI_Model_Overview] a
union all
SELECT 'Sales_2005.tblCustomerPersonDetails' AS TableName,b.SalesID,b.SalesPersonName, b.Location
FROM [EMS4_contract_DB_Phase_Four].[dbo].[SK_APC_PI_Model_Overview] b
) tmp
GROUP BY [ID],[Name], Location
Having Count(*) = 1
Order by [Name]





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Identify the Table Data Difference  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Getting multiple row values in a single cell separated by comma`s in sql
Previous Resource: Store Procedure to Generate Create Table Script
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use