View previous topic :: View next topic
|
Author |
Message |
Help-Me-Out
New User
Joined: 09 Dec 2006 Posts: 56 Location: Pune
|
|
|
|
Hi,
how to find the relation between the two tables i.e. how to find the which is primary key and foreign kay of the tables? |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Code: |
select colname from sysibm.sysforeignkeys where tbname = 'table name';
|
will give you the col which is the foreign key
now for primary key
select colname from sysibm.syskeys where ixname in
(select name from sysibm.sysindexes where tbname ='table name'); |
|
Back to top |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
you may get the details of the primary key with the following query as well :
SELECT NAME FROM SYSIBM.SYSCOLUMNS WHERE TBCREATOR = <TABLE CREATOR NAME> AND TBNAME = <TABLE NAME> AND KEYSEQ > 0;
(OR)
SELECT A.COLNAME, A.COLSEQ, A.ORDERING, FROM SYSIBM.SYSKEYS A, SYSIBM.SYSINDEXES B WHERE A.IXNAME = B.NAME AND A.IXCREATOR = B.CREATOR AND A.IXCREATOR = B.TBCREATOR AND B.TBNAME = <TABLE NAME> AND B.TBCREATOR = <TABLE CREATOR> AND B.UNIQUERULE = āPā; |
|
Back to top |
|
|
Help-Me-Out
New User
Joined: 09 Dec 2006 Posts: 56 Location: Pune
|
|
|
|
Thanks all for ur reply.. this is working |
|
Back to top |
|
|
|