Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 Data replication from multiple Db2 ta... kishpra DB2 5 Mon Mar 27, 2017 9:58 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm
No new posts find particular member name in PDS us... ravi243 CLIST & REXX 10 Mon Dec 19, 2016 6:44 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us