Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
To find Primary key in a table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: To find Primary key in a table
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

Site Director


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

PostPosted: Mon Feb 01, 2010 6:03 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Feb 04, 2010 11:17 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Feb 05, 2010 2:09 am    Post subject:
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
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/dsnsqj10/F.30


SYSKEYS:
http://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    Post subject: Reply to: To find Primary key in a table
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

Site Director


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

PostPosted: Fri Feb 05, 2010 8:15 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts PC (UTF-8) -> z/OS (EBCDIC) -> ... prino All Other Mainframe Topics 4 Fri Sep 01, 2017 1:47 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us