query a table such that it is comparable

Posted on 2011-05-08
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

    Author Comment

    Pls note a table may not have primary keys set.

    Author Comment

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

    Expert Comment

    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

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

    Accepted Solution

    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

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now