Home      Mainframe Forum      Mainfarme Tutorials      IBM Manuals      Mainframe Interview Questions      Mainframe Books      IT News     SiteMap     Downloads


     
 
MAINFRAME - TIP OF THE DAY : programming pearls - The fastest algorithm can frequently be replaced by one that is almost as fast and much easier to understand.

Google
 
Web mainframegurukul.com

Welcome to the mainframegurukul forums.

You are currently viewing our mainframe forums as a guest which gives you limited access to view most discussions, articles. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support at admin@mainframegurukul.com


How to know the Primary and Foriegn keys?

 
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> DB2 SQL - DB2 PROGRAMMING
  View previous topic :: View next topic  
Author Message
arrbee
Active Member


Joined: 24 Feb 2006
Posts: 147

PostPosted: Fri Feb 24, 2006 1:36 pm    Post subject: How to know the Primary and Foriegn keys? Reply with quote

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.
_________________
Arr Bee
-------------
?My joy in learning is partly that it enables me to teach? - Seneca(Roman philosopher, mid-1st century AD)
Back to top
View user's profile Send private message Send e-mail

pkaushi
Member


Joined: 06 Feb 2006
Posts: 9

PostPosted: Fri Feb 24, 2006 2:40 pm    Post subject: Reply with quote

Quote:


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 Smile

_________________
Thanks and Regards,
Prashant
Back to top
View user's profile Send private message
Kalicharan
Moderator


Joined: 08 Feb 2006
Posts: 31

PostPosted: Mon Mar 13, 2006 7:12 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Kalicharan
Moderator


Joined: 08 Feb 2006
Posts: 31

PostPosted: Wed Mar 15, 2006 3:36 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
arrbee
Active Member


Joined: 24 Feb 2006
Posts: 147

PostPosted: Thu Mar 16, 2006 10:37 am    Post subject: Reply with quote

Thanks Kalicharan. Sadly, we don't have File-Aid for DB2. I will try the other method told by you.

Thanks a lot.
_________________
Arr Bee
-------------
?My joy in learning is partly that it enables me to teach? - Seneca(Roman philosopher, mid-1st century AD)
Back to top
View user's profile Send private message Send e-mail
vijay
Guest





PostPosted: Tue May 09, 2006 5:22 am    Post subject: finding the primar key.... Reply with quote

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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> DB2 SQL - DB2 PROGRAMMING All times are GMT + 5 Hours
Page 1 of 1



 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts Sr. System Programmer - IMS/DB2/CICS - Trivandrum 8+ yrs Exp 0 koolguy_1983 487 Fri Jan 15, 2010 3:34 pm
koolguy_1983 View latest post
No new posts main & sub programs using the same table !! 1 arrbee 2638 Tue Mar 10, 2009 3:02 pm
Anuj Dhawan View latest post
No new posts db2 query 4 thiyagucse 5589 Fri Aug 29, 2008 10:31 am
Krishna View latest post
No new posts How to find out the record length using tso command? 4 bsriram 9119 Fri Oct 26, 2007 12:17 am
varun View latest post
No new posts Programmer/Analyst in Belgium 0 nicksnels 1396 Wed Apr 04, 2007 1:59 pm
nicksnels View latest post
 



This widget requires Flash Player 9 or better








Go to top of the page
 

Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  DB2 INTERVIEW QUESTIONS ||  COBOL INTERVIEW QUESTIONS  ||  JCL INTERVIEW QUESTIONS ||  JCL2 INTERVIEW QUESTIONS ||  VSAM INTERVIEW QUESTIONS ||  CICS INTERVIEW QUESTIONS  ||  Online tutorials ||  Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  SiteMap  ||  Expeditor Tutorial  ||  FILE-AID Tutorial  ||  Changeman Tutorial  ||  COBOL   ||  DB2   ||  JCL  ||  CICS  ||  VSAM  ||  DB2 Interview Questions ( 110 )   || Simple JCL Tutorials  || JCL Tutorial from MainframeGurukul.com   || Simple JCL Tutorial - Chapter1 ;|| Mainframe Forum - Tutorials  || Mainframe Tutorials

Drona Educational Forums - Mainframe Cobol DB2 CICS Board
Powered by phpBB