View previous topic :: View next topic
|
Author |
Message |
amrita.chatterjee
New User
Joined: 27 Apr 2006 Posts: 48 Location: Bangalore, India
|
|
|
|
Hi,
If the two tables are related in DB2(Say Table T000 & T001 and Table T000 is the parent table & T001 is the child table) so could you please tell me where I can find the following:
1.relation between these two tables
2.which column is common between two tables
Actually I'm not able to find out the relation in DDL.
Could you please help me in this regards? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If you look at the data columns and index definitions for the 2 tables, the relationship should be apparent.
It may be that the relationship is not obvious (it should be, but sometimes data structures are not as well defined as they could be). Look for a column in the "parent" that has a similar definition in the "child" that is an index (or part of an index) in the child. Again, it is usually the primary key, but it does not have to be. |
|
Back to top |
|
|
amrita.chatterjee
New User
Joined: 27 Apr 2006 Posts: 48 Location: Bangalore, India
|
|
|
|
Actually I have checked the DDL of the two tables and also whatever index has been defined on the tables but no such primary key, FOREIGN KEY or REFERENCES are present. Is there any other way to find the relation? |
|
Back to top |
|
|
mkk157
Active User
Joined: 17 May 2006 Posts: 310
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If the tables have no common column(s) that are keyed (at least in the child), why do you consider them related?
Consider - If one of the tables is about employees and the other about mechanical components, they are not likely related at all. . .
If you describe what kind of data each table contains, that may help. |
|
Back to top |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
If the DBAs are using referential integrity you could query the catalog to fish this information out. However, it is not a foolproof approach.
You could query the SYSIBM.SYSCOLUMNS to which column names are used in more than one table. Again - not foolproof.
What we do here is this: We go to the DBAs and ask to see the data model. Nice boxes that represent tables - lines drawn from box to box that indicate 1-1 relationships / 1-to-many / many-to-many, etc. This is the proper way to get an understanding of your database. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Or none-to-none
Gotta love Entity Relationship Diagrams |
|
Back to top |
|
|
amrita.chatterjee
New User
Joined: 27 Apr 2006 Posts: 48 Location: Bangalore, India
|
|
|
|
Hi,
Thanks for all the reply. I got lot of information from this.
Actually i think I can better describe the situation by the following example.
Table T000 >> has two column with name TBL_ID & TBL_PTR
Say value of these two columns are
TBL_ID TBL_PTR
T001 001
T024 012 like this.
Now T001, T024, these are again some tables.
So in those tables also same pointer colume is present and also other columns are present. So Just to take the correct entry from T001, I have to check the pointer in T000 & then with that pointer I have to go to the T001 & fetch the exact row.
For this reason only, I'm thinking that, these T000, T001 should be related.
For this reason, I have already checked the index of these two tables & DDL of these two Tables but I'm not able to find any relation.
Then I have run the following query:
SELECT TBCREATOR, TBNAME, NAME, KEYSEQ
FROM SYSIBM.SYSCOLUMNS
WHERE TBCREATOR = 'XXXXXX'
AND TBNAME = 'T000'
AND KEYSEQ > 0
ORDER BY KEYSEQ;
But after running this query, I can found out that the value of KEYSEQ of every column is 0.
I'm not able to really understand how the relation has been established.
Thanks & Regards
Amrita. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
From what you have posted so far, i see no true relationship, but i could be misunderstanding. If you explain differently, that may help.
Quote: |
For this reason, I have already checked the index of these two tables & DDL of these two Tables but I'm not able to find any relation.
|
What is it that you are looking for?
You might try
instead of
Quote: |
So Just to take the correct entry from T001, I have to check the pointer in T000 & then with that pointer I have to go to the T001 & fetch the exact row. |
Please clarify what this is telling us. It sounds like when you have a ptr value you need to read the row with the same ptr value.
What i guess i'm saying is that i do not yet understand what info you are looking for
If we persist, we will get there |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello amrita.chatterjee,
Have you found what you needed? |
|
Back to top |
|
|
|