Mainframe: How to find Primary Key in Zos DB2

DB2+PrimaryKeySPUFI is a tool being used in mainframe to interact with DB2. In mainframe, when a Table is created by DBA, for developers, it is not possible to see Table description details.

As everyone aware that when TABLE is created in DB2, the details store in DB2 SYSTEM catalog tables.

To check PRIMARY KEY you need to write a SQL query on SYSIBM.SYSCOLUMNS catalog table:

There are 2 ways can see Primary Key Column name:

  • Using Tools like BMC/ Toad Tools
  • Other way is using SQL Query

Below SQL query works to know primary key:

SELECT NAME
 FROM SYSIBM.SYSCOLUMNS
 WHERE TBNAME = 'DEPT'
 AND TBCREATOR = 'DSN8910'
 AND KEYSEQ>0
 GROUPBY KEYSEQ ASC;

From the result of above query you will get column name on which primary key is defined.

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.

Comments are closed.