Click here to Skip to main content
15,845,785 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:

I want to compare 3 databases and show its difference.
Can anyone help me to understand the logic behind it?
Like how should i start the comparison.


Suppose i have 3 databases.

1st database has 4 tables
2nd database has 2 tables and 3rd database has 4 tables
so in this case the difference is 2 tables are missing in 2nd database.

2) All the databases have 4 tables then it should check for change in structure if any like no. of columns or data types.

3)If databases have triggers or functions then those should be compared line by line and difference should be highlighted with colors.

Hope this explains my questions.

Updated 13-Jan-14 9:37am
OriginalGriff 13-Jan-14 14:03pm    
Depends on how you want to compare them: are you looking for unique rows, missing rows, older rows, newer rows, or what?
"compare" covers a lot of ground...

Use the "Improve question" widget to edit your question and provide better information.
Dave Kreskowiak 13-Jan-14 14:30pm    
On top of what OriginalGridd said, are you talking about comparing the data in the tables or the schema of the database? Without a definition of exactly what you mean by "compare" it's going to be impossible to answer your question.

If you don't have that term defined precisely, you're also going to find it impossible to write the code to do it!
[no name] 13-Jan-14 14:52pm    
you want to do it in your code or you are looking for a tool ?
archies_gall 14-Jan-14 13:48pm    
I want to develop a tool which will compare 3 databases
ZurdoDev 13-Jan-14 15:25pm    
I would recommend getting a 3rd party product that can do that. Search google. That will be way easier than you trying to do it.

1 solution

Many years ago I wrote an app to do that. It was against SQL Server and we had a Dev, Test, and Prod environments. To make life easier I only compared 2 at a time. You can do all that using the system tables.

I compared objects in the databases (tables, Stored Procedures, Functions, views etc) I would find what was missing in one then the other. I had it broken down into types just to make the UI easier.

If table structure was different I would put links to display the differences, Varchar(5) and Varchar(10)can make a huge difference!

I was even comparing the text in the stored procedures to display the ones that were different.

So you have to compare what exists in and what is missing, then compare the items like you were thinking. My biggest recommendation would be to only compare 2 at a time to save yourself a lot of work.

All the text for the stored procedures, functions and triggers is stored in the system tables so you can do easy SQL string compares.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900