Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB2 Table Layout Question 1

Status
Not open for further replies.

trmweb

Programmer
Dec 10, 2002
5
US
I'm trying to gather DB2 table/column layout information to build a data dictionary. I'm doing this on the mainframe with SPUFI because I lack third party software like BMC or Candle. I'm okay SELECTing from SYSIBM.SYSCOLUMN & SYSIBM.SYSTABLE tables. My question is -

How do I determine the primary key columns?
Any one have an example of gathering this info?

Thanks!
TRMWEB
 
Hello,

Try this:

SELECT A.NAME,B.NAME AS PRIMKEY
FROM SYSIBM.SYSTABLES A, SYSIBM.SYSCOLUMNS B
WHERE A.NAME = B.TBNAME
AND A.KEYCOLUMNS = B.COLNO ;

Helle
 
staland - that is exactly what I was looking for... thanks ... you get a star!
 
Following is the SQL I used to get what I needed --

SELECT TBCREATOR, TBNAME, NAME AS COLUMN_NAME,
KEYSEQ AS SEQ_#_OF_COL_IN_PK
FROM SYSIBM.SYSCOLUMNS

WHERE KEYSEQ > 0
AND TBNAME = 'table_name'
AND TBCREATOR = 'table_creator'
ORDER BY TBCREATOR, TBNAME, SEQ_#_OF_COL_IN_PK
;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top