473,586 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to list tables in order (parent & child relationship)

Is there a way to list (using db2 command or catalogs) to list hierarchy of
table parent & child relationship:

1) A list that shows which table should be deleted first,second,th ird...
2) A list that shows which table should loaded first, second,third...

Your help would be highly appreciated.

maricel.
Nov 12 '05 #1
3 19772
Yes, you can do that using the catalogs and a recursive common table
expression (CTE).
There are numerous examples on developerWorks.
To keep track of order you can mark the relationship.
google for: db2 node type
You will find an article by Jacques Roy that will be helpful

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Try this:

with leaf_children (leaf_child) as
(select tabname from syscat.tables where tabschema = 'DB2ADMIN'
and parents > 0 and children = 0 ),

refs (parentschema, parent, childschema, child, levels) as
((
select reftabschema, reftabname, tabschema, tabname, 4
from syscat.referenc es, leaf_children
where tabschema = 'DB2ADMIN'
and tabname = leaf_child)

union all

(select reftabschema, reftabname, tabschema, tabname, levels - 1
from refs r, syscat.referenc es s
where s.tabschema = r.parentschema
and s.tabname = r.parent
and r.levels > 0))

select distinct substr(r.parent ,1,20) as parent, '>>> ' ||
substr(r.child, 1,20) as child, levels
from refs r, (select parent, min(levels) as level
from refs group by parent) as p
where r.parent = p.parent and r.levels = p.level
union
select substr(leaf_chi ld,1,20), ' ', (select max(levels) from refs) +
1 from leaf_children
order by 3;

This recurses down the RI chain and gives an ordered list of parents
pointing to children. You need to set the number of levels you expect
(start with a pessimistically high number) by modifying the last
number on this line, above:

select reftabschema, reftabname, tabschema, tabname, 4

You'll also want to change the schema name in the query.

Hope that helps
Sean

"maricel" <ma*****@xtra.c o.nz> wrote in message news:<5a******* *************@n ews.xtra.co.nz> ...
Is there a way to list (using db2 command or catalogs) to list hierarchy of
table parent & child relationship:

1) A list that shows which table should be deleted first,second,th ird...
2) A list that shows which table should loaded first, second,third...

Your help would be highly appreciated.

maricel.

Nov 12 '05 #3
Hi,

I have developed a view, if you would like a copy let me know.

DBA.TABLE_LOAD_ SEQUENCE
- basically determines hierarchy of tables (recursively from
catalog) and displays them with a sequence number for loading (reverse
order for deleting)

Let me know if you would like a copy.

Paul.

"maricel" <ma*****@xtra.c o.nz> wrote in message news:<5a******* *************@n ews.xtra.co.nz> ...
Is there a way to list (using db2 command or catalogs) to list hierarchy of
table parent & child relationship:

1) A list that shows which table should be deleted first,second,th ird...
2) A list that shows which table should loaded first, second,third...

Your help would be highly appreciated.

maricel.

Nov 12 '05 #4

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

Similar topics

2
2275
by: Jeff | last post by:
Hello All: What I am trying to do is bind a textbox (really several text boxes) based on a list box selection. Basically what I'm dealing with are two tables with a 1 to 1 relationship. I have created the dataset and defined the relationship between the two tables in the schema. I add a list box to a form and set it's datasource to...
8
4322
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. Basically I want to say: If fk_ID is in list then do these statements to that record
6
10965
by: jalkadir | last post by:
Let's say that I have this class: class Parent{ private: char* str; public: const char* getStr(){return str;} }; And then I create a child class class Child{ private: std::string str; public: std::string& getStr(){return str;}
1
4020
by: DataB | last post by:
Hi Everyone! I have, essentially, two table structures in the same ms access database file. Both are of the parent-child format, one parent table with personal details, then multiple child tables keeping specific information, all child tables being linked to the parent in a 1-to-1 relationship on primary key value. I have 2 structures...
5
4923
by: MLH | last post by:
Cardinality? I hear it spoken of by MySQL users. Does it matter to MS Access if MySQL tables are attached via ODBC?
2
3057
by: Mindy | last post by:
Hey, I want to create links between my two tables. The primary keys of these two tables are character variables, with length =11. I followed exactly the instruction of Dummuy Book for ACCESS 2003. I click the primary key of table A , and hold and move the mouse to table B. But nothing happened. No line, no error reminders. Does anyone know...
4
1857
by: TGEAR | last post by:
Itemlookup table Field names : index_id (primary key), itemno, description. It has a child table, which is ItemPriceHistory table The relationship to the child table is one (parent table)-to-many (child table). - It is possible to have no child record for some rows in the parent table. ItemPriceHistory table Field names: index_id (primary...
4
2031
by: Frank List | last post by:
Hi, I've run into this problem many times and have not found a good solution yet. Here's what I have: table ParentTable - the "1" table table ChildTable- the "many" table ParentTable inner joined to ChildTable on ParentTable.ParentID =
5
2173
by: shapper | last post by:
Hello, I have the following list: <ul id="parent" class="parent"> <li> <img... </li> <ul id="child" class="child"> <li>Message 1</li>
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.