Find the primary key of the DB2 table.

RDBMS from IBM and IBM's Hierarchical DBMS and Transaction Manager (IMS DC).
Post Reply
Apurva Shelar
New Member
Posts: 5
Joined: Tue Sep 30, 2014 2:05 pm

Find the primary key of the DB2 table.

Post by Apurva Shelar »

Hi,

Is there any way to find the out primary key of a DB2 table? And also the length of the every column with out using any tools, like file-aid? Please help.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Find the primary key of the DB2 table.

Post by nicc »

No! You are going to least need a tool to read the DCLGEN for the table - ISPF Browse for example.
Regards
Nic
User avatar
Akatsukami
Global Moderator
Global Moderator
Posts: 122
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL
Contact:

Re: Find the primary key of the DB2 table.

Post by Akatsukami »

If Apurva-kun has SELECT access on SYSIBM.SYSINDEXES, does this not become a trivial query?
"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 826
Joined: Wed Sep 11, 2013 3:57 pm

Re: Find the primary key of the DB2 table.

Post by enrico-sorichetti »

And also the length of the every column with out using any tools
and SYSIBM.SYSCOLUMNS
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Find the primary key of the DB2 table.

Post by zprogrammer »

Please try this query ("untested")

Code: Select all

SELECT A.COLNAME,
       A.COLSEQ,
       A.ORDERING,
FROM SYSIBM.SYSKEYS A,
     SYSIBM.SYSINDEXES B
WHERE A.IXNAME = B.NAME
AND   A.IXCREATOR = B.CREATOR
AND   A.IXCREATOR = B.TBCREATOR
AND   B.TBNAME = <TABLE NAME>
AND   B.TBCREATOR = <TABLE CREATOR>
AND   B.UNIQUERULE = ‘P’
zprogrammer
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Find the primary key of the DB2 table.

Post by nicc »

And hw would you use that, Pandora? Remember - no tools! (And SPUFI is a tool.)
Regards
Nic
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Find the primary key of the DB2 table.

Post by zprogrammer »

We need to use that by executing a DSNTIAUL program
zprogrammer
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Find the primary key of the DB2 table.

Post by zprogrammer »

Or Even execute REXX (If TS has some basic knowledge to do with DSNREXX)
zprogrammer
Apurva Shelar
New Member
Posts: 5
Joined: Tue Sep 30, 2014 2:05 pm

Re: Find the primary key of the DB2 table.

Post by Apurva Shelar »

By without any tools, I meant tools like file-aid or IBM file manager. I did not mean to go to mainframes barefooted.

Thanks Pandora-Box, your query has helped. I also looked at these two queries and they were also helpful: http://publibz.boulder.ibm.com/cgi-bin/ ... 0718164132
E.8 Retrieving catalog information about parent keys


SYSIBM.SYSCOLUMNS identifies columns of a parent key in column KEYSEQ; a nonzero value indicates the place of a column in the parent key. To retrieve the creator, database, and names of the columns in the parent key of the sample project activity table using SQL statements, execute:

Code: Select all

SELECT TBCREATOR, TBNAME, NAME, KEYSEQ
       FROM SYSIBM.SYSCOLUMNS
       WHERE TBCREATOR = 'DSN8710'
       AND TBNAME = 'PROJACT'
       AND KEYSEQ > 0
         ORDER BY KEYSEQ;
SYSIBM.SYSINDEXES identifies the primary index of a table by the value P in column UNIQUERULE. To find the name, creator, database, and index space of the primary index on the project activity table, execute:

Code: Select all

SELECT TBCREATOR, TBNAME, NAME, CREATOR, DBNAME, INDEXSPACE
       FROM SYSIBM.SYSINDEXES
       WHERE TBCREATOR = 'DSN8710'
       AND TBNAME = 'PROJACT'
       AND UNIQUERULE = 'P';
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Find the primary key of the DB2 table.

Post by zprogrammer »

Glad it helped
zprogrammer
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DB2 and IMS DB/DC”