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

How can I find the Primary key of a table?


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

New User


Joined: 18 May 2003
Posts: 7
Location: Bangalore

PostPosted: Sun Feb 15, 2004 8:54 pm
Reply with quote

Dear Guys,

Can anybody clear:

How to identify my primary key of the table, if I don't have permission to view SYSIBM.* Tables............
Back to top
View user's profile Send private message
mcmillan

Site Admin


Joined: 18 May 2003
Posts: 1210
Location: India

PostPosted: Mon Feb 16, 2004 5:56 pm
Reply with quote

You can easily find it from the system catalog.

Or try to display all the columns of the table. The primary key column don't have any duplicates.(if its not a complex key)

If you have any other columns as unique, try to insert a duplicate value or NULL for each columns one by one.

Using this tech. you can easily identify the primary key.
Back to top
View user's profile Send private message
dhan_chander

New User


Joined: 26 Feb 2004
Posts: 1
Location: Chennai

PostPosted: Thu Feb 26, 2004 11:27 am
Reply with quote

Hi Mac,
I just tried selecting all the columns from the table, the display was in the order of insertion but not in ascending order. kindly make it clear.

Cheers
Viju icon_question.gif
Back to top
View user's profile Send private message
uvraman

New User


Joined: 05 Mar 2004
Posts: 2
Location: Bangalore

PostPosted: Fri Mar 05, 2004 4:53 pm
Reply with quote

Hi,

You can try running this SQL

SELECT * FROM SYSIBM.SYSKEYS
WHERE IXCREATOR='<creator name>'

This will give the column which is part of primary key along with the column number, colun sequence and ordering.

Hope this helps.
Back to top
View user's profile Send private message
Jaya kishan Y

New User


Joined: 04 Jan 2006
Posts: 1
Location: Trivandrum

PostPosted: Wed Jan 04, 2006 5:52 pm
Reply with quote

hai guys,

what is the exact reason for status code 4
Back to top
View user's profile Send private message
lkhiger

New User


Joined: 28 Oct 2005
Posts: 89

PostPosted: Thu Jan 05, 2006 3:46 am
Reply with quote

By using the "Platinum"
Back to top
View user's profile Send private message
winchaat

New User


Joined: 23 Mar 2005
Posts: 14

PostPosted: Thu Jan 05, 2006 11:54 am
Reply with quote

SELECT NAME FROM SYSIBM.SYSCOLUMNS WHERE TBCREATOR = 'tablecreator' AND TBNAME = 'tbaname' AND KEYSEQ > 0;

hope this helps...



---->RAG
Back to top
View user's profile Send private message
sairam

New User


Joined: 30 Aug 2005
Posts: 58
Location: Kolkata

PostPosted: Thu Jan 05, 2006 3:39 pm
Reply with quote

Quote:
SELECT * FROM SYSIBM.SYSKEYS
WHERE IXCREATOR='<creator name>'

For IXCREATOR use the following SQL
select Name from sysibm.sysindexes where tbname=<Table Name>
Back to top
View user's profile Send private message
ragshere

New User


Joined: 20 Dec 2004
Posts: 70

PostPosted: Tue Jan 10, 2006 3:12 pm
Reply with quote

Hi Manesh,

If you didn't have access to SYSIBM.* tables it is some what tough to find primary key.

If you have DBA admin panel , you can check Primary index on that table. so that you can determine the columns involved in that index.

If you didn't have admin panel,
Then get the distinct values for each column.
for any column ,If the count matches to the row count in the table that means that column has either unique constraint or primary key.

To findout whether it is unique or primary key , try to insert a NULL value in that column. If it accepts NULL ,it is a UNIQUE column otherwise primary key.

But this technique work only when primary key is defined on only single column.

Hope you got me..

Bye
Rags
Back to top
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Tue Jan 10, 2006 4:04 pm
Reply with quote

Hi Manesh,

Check this link for more information.

publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/E.8?DT=20010718164132

If you run your queries you might get -551 error which means that you do not have the Authorization to issue select statement on the catalog tables. Talk to your DBA and may be he can help out.


Hope this helps.
Back to top
View user's profile Send private message
futuredba

New User


Joined: 08 Jan 2006
Posts: 22
Location: Delhi

PostPosted: Tue Jan 10, 2006 7:42 pm
Reply with quote

Hi All,

We can also use FM/DB2 for this issue. Using this tool, if we open any table in edit or browse mode, then we will see 'PU' before column which is the primary key or a part of the composite primary key.
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