MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to find the primary key for DB2 table?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
sonika2008
Beginner


Joined: 17 Aug 2007
Posts: 20
Topics: 9

PostPosted: Wed Sep 05, 2007 8:07 am    Post subject: How to find the primary key for DB2 table? Reply with quote

Hi,

I have used these two queries for primary key -
1)SELECT * FROM SYSIBM.SYSKEYS
WHERE IXCREATOR='Creator';

2)SELECT NAME
FROM
SYSIBM.SYSCOLUMNS
WHERE TBNAME = 'Table Name'
AND TBCREATOR = 'Creator'
AND KEYSEQ > 0
ORDER BY KEYSEQ ASC

but for some tables these queries are not working.
Is there any other way from which I can find the primary key for DB2 tables?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Sep 05, 2007 8:16 am    Post subject: Reply with quote

sonika2008,

You should be checking SYSIBM.SYSINDEXES. Also it is not always possible to retrieve information about unique keys Created before Version 7. Information can be retrieved for unique Keys created in Version 7 and for unique keys created before Version 7 if they are not involved in referential integrity.

Any way check this link

http://www.mvsforums.com/helpboards/viewtopic.php?t=24&highlight=parent

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sonika2008
Beginner


Joined: 17 Aug 2007
Posts: 20
Topics: 9

PostPosted: Wed Sep 05, 2007 8:48 am    Post subject: Reply with quote

Thanks for your quick response!!

Actually, I was trying to find primary key in order to uniquely identify the rows for comparison purpose (I am unloading 2 versions - older and newer - of Image copies of DB2 tables and then I need to compare those 2.)

But, now, as you say, if I can't find primary key for older tables which were created before version 7, Can you please suggest me any other way by which I can uniquely identify the rows?
Back to top
View user's profile Send private message
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Wed Sep 05, 2007 8:56 am    Post subject: Reply with quote

1. even the old record and the new reord with the primary key, they may be different too (not primary key columns have been updated)

2. Why not sort the 2 unloaded files in the same order, and use SUPERC utility to compare them.
Back to top
View user's profile Send private message
sonika2008
Beginner


Joined: 17 Aug 2007
Posts: 20
Topics: 9

PostPosted: Wed Sep 05, 2007 9:30 am    Post subject: Reply with quote

Thanks for your reply.

I have used SUPERC utility for comparison, but its not working fine for millions of record.Right now I am using the File-manger compare utility, for that compariosn I need to give the primary key fields as per my output requirement.

So plz give suggestion to find out the primary key or unique column in table
Back to top
View user's profile Send private message
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Wed Sep 05, 2007 10:01 am    Post subject: Reply with quote

Code:

1. query SYSIBM.SYSINDEXES
    where UNIQUERULE='P'
    get the primary index name
2. query SYSIBM.SYSKEYS
    get the primary key column
SQL sample:
 select COLNAME,COLSEQ from SYSIBM.SYSKEYS
   where (IXNAME,IXCREATOR) in
      (SELECT NAME,CREATOR from SYSIBM.SYSINDEXES
         where TBNAME = xxx and TBCREATOR = xxx)

Note: Primary key is not mandatory, some table may have no primary key
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group