---
title: "Mainframe: How to find Primary Key in Zos DB2"
description: "Knowing Primary Key on which column of Table it is defined is a tricky in mainframe zo/s DB2. This SQL query helps to find column name of table on which it is defined. Very useful query for mainframe developers working on DB2."
url: https://srinimf.com/2010/07/22/db2-how-to-find-primary-key/
date: 2010-07-22
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2010/07/pexels-photo-6180668.jpeg?fit=1880%2C1253&ssl=1
categories: ["DB2", "DB2 V11"]
tags: ["DB2 Tips and Solutions", "Primary Key"]
type: post
lang: en
---

# Mainframe: How to find Primary Key in Zos DB2

SPUFI 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.

## Primary key

As everyone aware that when TABLE is created in DB2, the details store in DB2 [SYSTEM catalog](https://srinimf.com/2023/04/03/how-to-register-stored-procedures-in-a-db2-catalog-table/) tables.

**To check [PRIMARY KEY](https://srinimf.com/2016/08/04/how-db2-primary-key-differ-from-other-rdbms-databases/) you need to write a [SQL query](https://srinimf.com/2018/10/23/ordering-sql-query-results-using-desc-vs-asc/) on SYSIBM.SYSCOLUMNS [catalog table](https://srinimf.com/2016/09/22/how-to-analyze-sql-query-the-best-way/):**

There are 2 ways can see [Primary Key](https://srinimf.com/2015/08/18/db2-questions-on-primary-key-view-static-sql-and-dynamic-sql/) Column name:

- Using Tools like BMC/ Toad Tools
- Other way is using [SQL Query](https://srinimf.com/2010/07/04/db2-row-number/)

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.

Related[ObjectStar One-stop Material to Refresh Quickly](https://srinimf.com/2012/06/02/mainframe-with-objectstar-material/)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2010%2F07%2F22%2Fdb2-how-to-find-primary-key%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2010%2F07%2Fpexels-photo-6180668.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=Mainframe%3A%20How%20to%20find%20Primary%20Key%20in%20Zos%20DB2)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2010/07/22/db2-how-to-find-primary-key/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2010/07/22/db2-how-to-find-primary-key/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2010/07/22/db2-how-to-find-primary-key/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2010/07/22/db2-how-to-find-primary-key/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Mainframe%3A%20How%20to%20find%20Primary%20Key%20in%20Zos%20DB2&body=https%3A%2F%2Fsrinimf.com%2F2010%2F07%2F22%2Fdb2-how-to-find-primary-key%2F&share=email)
-

### Like this:

Like Loading…
