How to find the primary key of a DB2 table TAB1?

DB2DatabaseBig Data Analytics

We can find the primary key of any table using the SYSIBM.SYSCOLUMNS table. The SYSIBM.SYSCOLUMNS is a DB2 system table which contains one row for every column of each table. It also contains the data related to the views. Below SQL query can be fired in order to find the primary key of a particular table.

SELECT NAME
FROM
SYSIBM.SYSCOLUMNS
WHERE TBNAME = 'TAB1’
AND KEYSEQ > 0
ORDER BY KEYSEQ ASC;

We will use our table name in the TBNAME column of SYSCOLUMNS table using the WHERE clause and KEYSEQ > 0 will return only primary keys.

raja
Published on 12-Sep-2020 18:08:32
Advertisements