Assumptions:
- The same query is ran on both tables
- Both tables reside in different schemas
- Database tables are a part of may or may not be the same
- If Databases are not the same, there is no guarantee that their version or patch level
- The order of data is the same across both tables. Data is sorted
- It is possible that one table has more columns then the other
- It is possible that one table has more rows then the other
As i see it there are 2 distinct challanges
- Running comparison
- Producing a legible report outlining the differences
I wonder if the following approach would work
If (table1 and table 2 have the same number of columns)
For every row found in table1 check
If that same identical row exists in table2
And if it does not due to some column mismatch
Find the closes match possible and report column differences
If best match can be discovered, report column difference, else
report can result is ambiguous
...
Is this a reasonable approach? Given some of the Assumptions above, can you recommend an alternative?
My answer would be to use red-gate SqlCompare.
They have a schema and a data compare tool, there tools also allow you to generate script to make one DB look like the other.
I have no connection with red-gate other then as a customer