IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

To find Primary key in a table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
meenakshi_forum
Warnings : 1

Active User


Joined: 27 May 2008
Posts: 121
Location: India

PostPosted: Mon Feb 01, 2010 5:15 am
Reply with quote

Hi,

Can anyone give me the syntax to find primary key of a table?

Thanks.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Feb 01, 2010 6:03 am
Reply with quote

Hello,

Use the forum SEARCH. There is posted info on how to identify the primary key.
Back to top
View user's profile Send private message
Ragav86

New User


Joined: 27 Jan 2010
Posts: 37
Location: chennai

PostPosted: Thu Feb 04, 2010 10:58 pm
Reply with quote

Use this


select name
from sysibm.syscolumns
where tbname = 'xxxx'
and tbcreator ='yyyyy'
and keyseq>0
order by keyseq;
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Feb 04, 2010 11:17 pm
Reply with quote

Hello,

Why do you believe this will identify the primary key?
Back to top
View user's profile Send private message
Ragav86

New User


Joined: 27 Jan 2010
Posts: 37
Location: chennai

PostPosted: Fri Feb 05, 2010 1:41 am
Reply with quote

syscolumns will have the information about the primary keys
so i am using this query to get the primary key information.
please en light me if i am wrong....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 05, 2010 2:09 am
Reply with quote

Hello,

Not necessarily wrong, but these offer more complete info about the index/key than syscolums does. . . Including the index name. . .

SYSINDEXES
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/dsnsqj10/F.30


SYSKEYS:
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/dsnsqj10/F.42
Back to top
View user's profile Send private message
tomehta

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Fri Feb 05, 2010 3:18 pm
Reply with quote

Hi Dick
Quote:

Not necessarily wrong


out of curosity, in which case the KEYSEQ will have a value other than zero, but still the corresponding colum will not be a part of key.

Regards
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 05, 2010 8:15 pm
Reply with quote

Hello,

Quote:
in which case the KEYSEQ will have a value other than zero

You misunderstand. . . I'll try again.

The values returned in your query will be parts of the key, but this is not the most complete info available.

Suggest you look thru the 2 links posted to see the kind of info more often wanted than just some column names.

Also, the original request was to "to find primary key" which (i believe) would at least include the name of the index. . .
Back to top
View user's profile Send private message
Ragav86

New User


Joined: 27 Jan 2010
Posts: 37
Location: chennai

PostPosted: Fri Feb 05, 2010 9:00 pm
Reply with quote

ya i got it thanks a lot.....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top