View previous topic :: View next topic |
Author |
Message |
sonika2008 Beginner
Joined: 17 Aug 2007 Posts: 20 Topics: 9
|
Posted: Wed Sep 05, 2007 8:07 am Post subject: How to find the primary key for DB2 table? |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Sep 05, 2007 8:16 am Post subject: |
|
|
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 |
|
 |
sonika2008 Beginner
Joined: 17 Aug 2007 Posts: 20 Topics: 9
|
Posted: Wed Sep 05, 2007 8:48 am Post subject: |
|
|
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 |
|
 |
videlord Beginner
Joined: 09 Dec 2004 Posts: 147 Topics: 19
|
Posted: Wed Sep 05, 2007 8:56 am Post subject: |
|
|
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 |
|
 |
sonika2008 Beginner
Joined: 17 Aug 2007 Posts: 20 Topics: 9
|
Posted: Wed Sep 05, 2007 9:30 am Post subject: |
|
|
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 |
|
 |
videlord Beginner
Joined: 09 Dec 2004 Posts: 147 Topics: 19
|
Posted: Wed Sep 05, 2007 10:01 am Post subject: |
|
|
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 |
|
 |
|
|