Hi,
It is asked in an interview that how to know the Primary and Foriegn keys of a DB2 Table? As a programmer, we generally don't have the DBA authority to look at the create table?
Is it possible to find out using SPUFI (SELECT * from table;)?
Please suggest.
How to know the Primary and Foriegn keys?
Moderators: Kalicharan, Moderator Group
How to know the Primary and Foriegn keys?
Arr Bee
-------------
?My joy in learning is partly that it enables me to teach? - Seneca(Roman philosopher, mid-1st century AD)
-------------
?My joy in learning is partly that it enables me to teach? - Seneca(Roman philosopher, mid-1st century AD)
Hi,
Theres a way to know the referential integrity constarints specified for the tables created by DBA's using the DB2Administration tool. Just type DB2A in teh command line and go browse the table. Give ddl against the table and it will list down teh sql query for the same. There you can find it out.
But if you dont use this tool Sorry will think of other alternative
Thanks and Regards,
Prashant
Prashant
- Kalicharan
- Moderator
- Posts: 31
- Joined: Wed Feb 08, 2006 1:51 pm
Hi,
With DB2-FileAID also we can find the PRIMARY & FOREIGN keys...
Fron DB2-FileAID,
--> 3.4
--> Mention Object Name & Object Type and select TABLE
--> I command against table (I --> Information)
-->Index Key Information(In this select Unique Key for Primary Key)
--> Related Table Information to get Foreign Key Information
Thanks
Kali
With DB2-FileAID also we can find the PRIMARY & FOREIGN keys...
Fron DB2-FileAID,
--> 3.4
--> Mention Object Name & Object Type and select TABLE
--> I command against table (I --> Information)
-->Index Key Information(In this select Unique Key for Primary Key)
--> Related Table Information to get Foreign Key Information
Thanks
Kali
- Kalicharan
- Moderator
- Posts: 31
- Joined: Wed Feb 08, 2006 1:51 pm
Hi,
This another way of knowing Primary Key and Foreign Keys using DB2 SYSDBASE table (SYSIBM)
For Primary Key==>
Select NAME from SYSIBM.SYSCOLUMNS
where TBCREATOR = XXXXX and TBNAME = XXXXX
and KEYSEQ > 0 order by KEYSEQ ASC
For Foreign Keys==>
Select A.REFTBNAME ,COLNAME FROM SYSIBM.SYSFOREIGNKEYS A, SYSIBM.SYSRELS B
WHERE A.RELNAME = B.RELNAME
AND A.TBNAME = XXXXX AND A.REFTBCREATOR = XXXXX
AND A.REFTBCREATOR = B.CREATOR
Thanks
Kali.
This another way of knowing Primary Key and Foreign Keys using DB2 SYSDBASE table (SYSIBM)
For Primary Key==>
Select NAME from SYSIBM.SYSCOLUMNS
where TBCREATOR = XXXXX and TBNAME = XXXXX
and KEYSEQ > 0 order by KEYSEQ ASC
For Foreign Keys==>
Select A.REFTBNAME ,COLNAME FROM SYSIBM.SYSFOREIGNKEYS A, SYSIBM.SYSRELS B
WHERE A.RELNAME = B.RELNAME
AND A.TBNAME = XXXXX AND A.REFTBCREATOR = XXXXX
AND A.REFTBCREATOR = B.CREATOR
Thanks
Kali.
finding the primar key....
Kalicharan wrote:Hi,
This another way of knowing Primary Key and Foreign Keys using DB2 SYSDBASE table (SYSIBM)
For Primary Key==>
Select NAME from SYSIBM.SYSCOLUMNS
where TBCREATOR = XXXXX and TBNAME = XXXXX
and KEYSEQ > 0 order by KEYSEQ ASC
For Foreign Keys==>
Select A.REFTBNAME ,COLNAME FROM SYSIBM.SYSFOREIGNKEYS A, SYSIBM.SYSRELS B
WHERE A.RELNAME = B.RELNAME
AND A.TBNAME = XXXXX AND A.REFTBCREATOR = XXXXX
AND A.REFTBCREATOR = B.CREATOR
Thanks
Kali.
hi kalicharan,
For finding primary key shd i use SYSIBM.SYSKEYS.
I am not sure abt it.will it work?
Thanks
R.Vijay
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page