473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Parent Child Relationship - System catalog tables

Is it possible to determine the list of child/parent tables for a
particular table from any system catalog tables? Using the
syscat.tables I'm able to retrieve the no of dependent parent/child
tables but unable to determine the list of dependent table name(s)

Example :
For a simple department-employee relationship, the following query
gives the count of parent/child tables but not the table names(s).

db2 => select tabname, parents,children from syscat.tables where
tabname = 'DEPA
RTMENT' or TABNAME = 'EMPLOYEE'

TABNAME PARENTS CHILDREN
----------------------------------------------------
DEPARTMENT 0 1
EMPLOYEE 1 0

2 record(s) selected.
Thanks,
Sam.

May 29 '06 #1
3 11291
syscat.references
TABSCHEMA/TABNAME shows children
REFTABSCHEMA/REFTABNAME shows parents
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 29 '06 #2
<re***********@gmail.com> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
Is it possible to determine the list of child/parent tables for a
particular table from any system catalog tables? Using the
syscat.tables I'm able to retrieve the no of dependent parent/child
tables but unable to determine the list of dependent table name(s)

Example :
For a simple department-employee relationship, the following query
gives the count of parent/child tables but not the table names(s).

db2 => select tabname, parents,children from syscat.tables where
tabname = 'DEPA
RTMENT' or TABNAME = 'EMPLOYEE'

TABNAME PARENTS CHILDREN
----------------------------------------------------
DEPARTMENT 0 1
EMPLOYEE 1 0

2 record(s) selected.
Thanks,
Sam.


It is in there somewhere. Try looking at the constraints.
May 29 '06 #3
re***********@gmail.com wrote:
Is it possible to determine the list of child/parent tables for a
particular table from any system catalog tables? Using the
syscat.tables I'm able to retrieve the no of dependent parent/child
tables but unable to determine the list of dependent table name(s)


This all depends on depends on the declared foreign key constraints. If
you have defined the relationships, then this is possible. Serge
pointed out that these can be found in the SYSCAT.REFERENCES table. In
order to traverse the tree structure, a recursive query can be used.
Assuming you have the same schema name for all of the tables, the
following query should give you a list of parent/child relationships
including how many levels deep the relationship between the top level
table and any subservient table:
WITH parentchild
(
parentname,
childname,
depth
) AS
(SELECT reftabname,
tabname,
1
FROM syscat.references
WHERE reftabname= 'DEPARTMENT'
UNION ALL
SELECT child.reftabname,
child.tabname,
depth+1
FROM parentchild parent,
syscat.references child
WHERE parent.childname = child.reftabname
)
SELECT DISTINCT parentname,
childname,
depth
FROM parentchild
ORDER BY depth
Hope this helps,
Evan

May 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: php newbie | last post by:
Hello, I am relatively new to SQL Server, although I have used Oracle extensively. In Oracle, there are system tables that you can query in order to get a list of all schemas and all the...
0
by: Steve | last post by:
I have mixed managed/unmanaged C++ MFC application. The mainframe is MFC window and we added new managed form. How can I set parent/child relationship between the new managed form...
3
by: B-Dog | last post by:
I'm trying to comprehend the database features in VB and after tons of reading I'm not sure how do relationships. I want to display a parent column and the respective child columns on one line of...
2
by: mkidd | last post by:
Hi, I'm new at vb .net and I have an issue that must be a common one, but I haven't found an example of it yet. I want to create parent-child relationships for 3 tables...
2
by: RJN | last post by:
Hi I need help in writing a recursive function. My table structure is as below. InstanceId LevelId ParentId 100 1 null 101 2 ...
0
by: CodeMonkey | last post by:
I'm using Visual Studio 2005 (vb.net). I have a dataset with 3 tables in it. I have a main table that has two fields in it, Category and Subcategory. I also have two other tables, one for...
0
by: vivajay | last post by:
I'm trying to do a parent/child relationship in nested datalists I have created. I do not want to repeat the contract number for each asset that falls within that contract number when I display each...
1
by: awesomewebsitesforyou | last post by:
Learn DB2 system catalog tables http://db2examples.googlepages.com/systemcatalogtables
1
by: Alex Benitez | last post by:
I want to have a form with 2 subforms...1 subform would be the parent table...and the 2nd subform would be the child table and they both would be in datasheet view. I want to see all records in the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.