Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

what're Oracle equivalent of DB2 sysibm.sysindexes,sysibm.sysrels

Posted on 2004-09-10
8
Medium Priority
?
1,668 Views
Last Modified: 2008-01-09
Hi,
I have the following two queries from db2 system tables to return primary key and a list of children tables of a given table

Could anybody help to convert them to Oracle equivalent

1. SELECT colnames
                FROM sysibm.sysindexes
                  WHERE tbName = 'mytableName' AND
                  uniquerule = 'P' AND colcount = 1

2.
SELECT tbname, fkcolnames
                  FROM sysibm.sysrels
                  WHERE reftbname = 'myTableName'
                  ORDER BY timestamp

Thanks.
0
Comment
Question by:oldyyy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 23

Assisted Solution

by:seazodiac
seazodiac earned 600 total points
ID: 12029953
sure. try this:

1.

SELECT column_name
FROM all_ind_columns
WHERE table_name= '<table name in CAPS>'
AND column_position=1;


0
 
LVL 23

Expert Comment

by:seazodiac
ID: 12029993
2.

select table_name, column_name
from all_cons_columns A, all_constraints B
where A.constraint_name=B.constraint_name
and B.constraint_type='R'
and  table_name='<table_name in CAPS>'
0
 
LVL 3

Assisted Solution

by:dnarramore
dnarramore earned 600 total points
ID: 12030090
1.

select all_ind_columns.column_name
from all_indexes,
     all_ind_columns
where all_indexes.index_name = all_ind_columns.index_name
and  all_indexes.table_owner = all_ind_columns.table_owner
and uniqueness = 'UNIQUE'
and all_indexes.table_name = 'MyTableName'
and all_indexes.index_name || all_indexes.table_owner in (select index_name || table_owner
                   from all_ind_columns
                           group by index_name, table_owner
                           having count(*) > 1)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:oldyyy
ID: 12030776
Thanks seazodiac and dharramore.

seazodiac's1 give me a list of 6 rows on oracle, where the db2 one only returned one row--> the first row.
Seazodiac's 1 is equivalent to the following db2  
SELECT colnames
                FROM sysibm.sysindexes
                  WHERE tbName = 'mytableName'
 

( without uniquerule = 'P' AND colcount = 1)


seazodiac's 2 give me 0 rows, where the db2 one returned 4 rows on db2 database.

dnarramore's 1 gives me 0 rows

Could anyone help again?
Thanks
0
 
LVL 23

Expert Comment

by:seazodiac
ID: 12032095
oldyyy:

Here is the explanation for my first query to return 6 rows in oracle but the similar query return only 1 rows.

that's because when you have "colcount=1" and "uniquerule='P'" in the where clause, you are limited the ONLY PRIMARY KEY column in the MytableName , and conceivably, you have only one PRimary key in one table.

the similar query in Oracle will return all the Indexed columns including PRIMARY key (because Oracle db will create a unique index on PK by default).

0
 
LVL 23

Expert Comment

by:seazodiac
ID: 12032139
just to add, still on the first question, colcount in IBM sysindexes table means the number of columns in the index.

so your original query is trying to get the single-column Primary key from sysindexes table.

there is really no need to try to find the matching query, as long as you are getting comfortable with Metadata in each database, you will get what you want.
0
 
LVL 13

Accepted Solution

by:
riazpk earned 800 total points
ID: 12034073
1.
SELECT column_name
FROM all_ind_columns a
WHERE table_name= '<table name in CAPS>'
AND column_position=1
and
exists (select null from all_indexes b where a.index_name=b.index_name and UNIQUENESS='UNIQUE')

OR

select column_name
FROM all_ind_columns a, all_indexes b
WHERE table_name= '<table name in CAPS>'
and a.index_name=b.index_name
and UNIQUENESS='UNIQUE'
AND column_position=1
0
 
LVL 13

Expert Comment

by:riazpk
ID: 12034087
(2)

select column_name,position
from all_cons_columns a, all_constraints b
where b.table_name='TABLEName'
and a.constraint_name=b.constraint_name
and constraint_type='R'
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

597 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