AuthorityBase is an IT knowledgebase dedicated to the world of databses and RDBMS systems by David Yahalom. Here you'll find articles, tips and general knowledge about Oracle, DB2 LUW, Sql Server, MySql and more. I hope you'll enjoy your stay.

20th
SEP

Quickly find foreign-keys depended tables

Posted by David Yahalom under DB2 LUW

[Digg] [Facebook] [Google] [Reddit] [Slashdot] [StumbleUpon]

Today I needed a quick way to find out all of the tables foreign keys are referencing for a given table. That is, if I have a table named TABLE1 which has a few foreign keys defined on it, I want a list of all the tables these foreign keys are referencing.

The easier way to do this is by querying the the database catalog tables (’data dictionary’). It took me some googleing to find out exactly what DB2 system catalog contains the relevant foreign key information.

SYSCAT.SYSRELS

You can easily use the following query to get a list of all tables referenced via the foreign keys of a given table(s):

select distinct reftbname
from sysibm.sysrels
where tbname in ('TABLE1', TABLE2', 'TABLE3')

Leave a Reply

AuthorityBase by David Yahalom is powered by Wordpress. Designed by Free WordPress Themes.