query a table such that it is comparable

Posted on 2011-05-08
Medium Priority
Last Modified: 2012-05-11
I need to compare a table stored in sybase12, sybase 15, oracle 11g. Ideally the table should be identical across the three databases but i need to comparae it any way. so what is the query i should run on all the three DBs that gives me a comparable set of records.

My belief is that Select * from table_name may return unordered rows from these three DBs which would inturn not be comparable i.e I may be comparing record 10 of sybase with record 50 of oracle and such.

Should i order my query by the primary key? If yes then How do i retrieve the all the primary key column of a table?

Should I order by all the columns of the table one by one like select * from table_name order by col1, col2, col3...coln. will this not exponentally increase the responce time?

What should be the ideal aproach?

Question by:PearlJamFanatic
  • 3

Author Comment

ID: 35717794
Pls note a table may not have primary keys set.

Author Comment

ID: 35717808
There are table that have 2-5 million records. should order by on all columns make a considerable difference?
LVL 15

Expert Comment

ID: 35717926
I use .Net DataTable to allow a UI with DataGridView.
Then I shows Added rows, Deleted Rows, modified rows.
Over modified rows, I use Yelow color for modified values and ToolTip to show Old Value.

But this method uses PrimaryKey at DataTable level.
note that no primary key is required on DataBase, but PrimaryKey is validated on DataTable.
I think user interface is very important.

.Net also provides DataView.
This uses also Binary Tree for Sort Columns and not primary Key is required.
You can build a DataView1 on DataTable1, DataView2 on DataTable2 with same sort columns.
Then shows side with side not matching rows from DataView1 and DataView2.
But here the User interface is too complex (I Think).

Author Comment

ID: 35718645
There no ui. This is just a java utility that i writing that will do the comparision of the csv data dump.
LVL 27

Accepted Solution

wilcoxon earned 2000 total points
ID: 35721303
The ideal would be to order by the primary key.  How you obtain the primary key is different for each database.

In Sybase, iirc, you check sysindexes looking for indid = 0 or one of the option bits being set (there are two "option" fields in sysindexes - don't remember off-hand which field or bit).  Iirc (again), indid = 0 is sufficient for Sybase 12 but may not be for Sybase 15 depending on how you have the indexes/keys defined.

If you don't want to deal with that, ordering by each column in table order would be reasonable (but slow since it probably won't be indexed).

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question