Catalog information about foreign keys.

RDBMS from IBM and IBM's Hierarchical DBMS and Transaction Manager (IMS DC).
Post Reply
Disha Shetty
Registered Member
Posts: 20
Joined: Sat Aug 17, 2013 4:54 pm

Catalog information about foreign keys.

Post by Disha Shetty »

Hi,

Is there any way which helps to find the catalog information for the foregin keys in DB2? Or which system table should I look at to get this information Please help me on this.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Catalog information about foreign keys.

Post by nicc »

Try SYSIBM.SYSFOREIGNKEYS
Regards
Nic
User avatar
Anuj Dhawan
Founder
Posts: 2801
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Catalog information about foreign keys.

Post by Anuj Dhawan »

SYSIBM.SYSRELS contains information about referential constraints, and each constraint is uniquely identified by the creator and name of the dependent table and the constraint name (RELNAME). Extending on nicc' reply, nicc SYSIBM.SYSFOREIGNKEYS contains information about the columns of the foreign key that defines the constraint. To retrieve the constraint name, column names, and parent table names for every relationship in which the project table is a dependent, execute:

Code: Select all

SELECT A.CREATOR, A.TBNAME, A.RELNAME, B.COLNAME, B.COLSEQ,
           A.REFTBCREATOR, A.REFTBNAME
      FROM SYSIBM.SYSRELS A, SYSIBM.SYSFOREIGNKEYS B
      WHERE A.CREATOR = 'DSN8710'
      AND B.CREATOR = 'DSN8710'
      AND A.TBNAME = 'PROJ'
      AND B.TBNAME = 'PROJ'
      AND A.RELNAME = B.RELNAME
        ORDER BY A.RELNAME, B.COLSEQ;
You can use the same tables to find information about the foreign keys of tables to which the project table is a parent, as follows:

Code: Select all

    SELECT A.RELNAME, A.CREATOR, A.TBNAME, B.COLNAME, B.COLNO
      FROM SYSIBM.SYSRELS A, SYSIBM.SYSFOREIGNKEYS B
      WHERE A.REFTBCREATOR = 'DSN8710'
      AND A.REFTBNAME = 'PROJ'
      AND A.RELNAME = B.RELNAME
        ORDER BY A.RELNAME, B.COLNO;


Refer: http://publibz.boulder.ibm.com/cgi-bin/ ... 0718164132
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Disha Shetty
Registered Member
Posts: 20
Joined: Sat Aug 17, 2013 4:54 pm

Re: Catalog information about foreign keys.

Post by Disha Shetty »

Thanks nicc and Anuj.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DB2 and IMS DB/DC”