If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > unique index columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-03, 08:05
stuhogg stuhogg is offline
Registered User
 
Join Date: May 2003
Location: Belfast, N.I.
Posts: 7
unique index columns

Hi,

Am trying to extract info from sys tables regarding a unique index.
SYSINDEXES gives me a COLLCOUNT of 10. How do i determine what
those columns are ?

Any help appreciated !

/stu
Reply With Quote
  #2 (permalink)  
Old 10-15-03, 08:41
blom0344 blom0344 is offline
Registered User
 
Join Date: Jan 2003
Location: Zutphen,Netherlands
Posts: 256
stu,

look in the view:

SYSSTAT.INDEXES, the column are described in:

COLNAMES

INDNAME houses the indexname you are looking at.

This is a fun bit of SQL to purge the number of columns:

Select INDNAME,LENGTH(COLNAMES)-LENGTH(REPLACE(COLNAMES,'+','')) AS #COLUMNS from SYSSTAT.INDEXES
__________________
Ties Blom
Senior Application Developer BI
Getronics Healthcare
DB2,ORACLE,Powercenter,BusObj,Access,
SQL, SQL server
Reply With Quote
  #3 (permalink)  
Old 10-15-03, 08:45
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Stu,

To findout which indexes are unique:

SELECT indschema,indname,tabschema,tabname from syscat.indexes where uniquerule <> 'D'

This will return all indexes that do not allow duplicates, including primary key indexes. If you do not want the primary keys, change the predicate to: "uniquerule = 'U'

To see the columns of an index:

SELECT colname,colorder from syscat.indexcoluse where indschema = ?? and indname = ?? order by colseq

HTH

Andy
Reply With Quote
  #4 (permalink)  
Old 10-15-03, 09:07
stuhogg stuhogg is offline
Registered User
 
Join Date: May 2003
Location: Belfast, N.I.
Posts: 7
Guys,

Thanks for the response. I can't find the view / tables you refer me to.
I'm on V7 for OS/390. All my catalog tables are qualified by SYSIBM. Whats the story ?

/stu

Quote:
Originally posted by ARWinner
Stu,

To findout which indexes are unique:

SELECT indschema,indname,tabschema,tabname from syscat.indexes where uniquerule <> 'D'

This will return all indexes that do not allow duplicates, including primary key indexes. If you do not want the primary keys, change the predicate to: "uniquerule = 'U'

To see the columns of an index:

SELECT colname,colorder from syscat.indexcoluse where indschema = ?? and indname = ?? order by colseq

HTH

Andy
Reply With Quote
  #5 (permalink)  
Old 10-15-03, 09:25
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Stu,
Sorry, I cannot help with OS/390. If you mentioned that in you initial post, you might have received a more relevant response.

Andy

Quote:
Originally posted by stuhogg
Guys,

Thanks for the response. I can't find the view / tables you refer me to.
I'm on V7 for OS/390. All my catalog tables are qualified by SYSIBM. Whats the story ?

/stu
Reply With Quote
  #6 (permalink)  
Old 10-15-03, 09:27
stuhogg stuhogg is offline
Registered User
 
Join Date: May 2003
Location: Belfast, N.I.
Posts: 7
Sorry Andy, thought most people were on mainframes !

Quote:
Originally posted by ARWinner
Stu,
Sorry, I cannot help with OS/390. If you mentioned that in you initial post, you might have received a more relevant response.

Andy
Reply With Quote
  #7 (permalink)  
Old 10-15-03, 09:40
blom0344 blom0344 is offline
Registered User
 
Join Date: Jan 2003
Location: Zutphen,Netherlands
Posts: 256
Don't know OS/390 either, but how about database VIEWS instead of tables. Most databases have sets of views specifically for DBA information (for easier reference. that is)
__________________
Ties Blom
Senior Application Developer BI
Getronics Healthcare
DB2,ORACLE,Powercenter,BusObj,Access,
SQL, SQL server
Reply With Quote
  #8 (permalink)  
Old 10-15-03, 11:06
aloz aloz is offline
Registered User
 
Join Date: May 2003
Location: San Juan, PR
Posts: 18
For OS/390 you can try this:

SELECT TBNAME, NAME, UNIQUERULE, COLNAME, COLSEQ, ORDERING
FROM SYSIBM.SYSINDEXES A, SYSIBM.SYSKEYS B
WHERE B.IXNAME = A.NAME AND A.UNIQUERULE <> 'D'
ORDER BY 1, 2, 5

Saludos, Antonio
Reply With Quote
  #9 (permalink)  
Old 10-15-03, 12:35
stuhogg stuhogg is offline
Registered User
 
Join Date: May 2003
Location: Belfast, N.I.
Posts: 7
Excellent !

You are the man Antonio !

Quote:
Originally posted by aloz
For OS/390 you can try this:

SELECT TBNAME, NAME, UNIQUERULE, COLNAME, COLSEQ, ORDERING
FROM SYSIBM.SYSINDEXES A, SYSIBM.SYSKEYS B
WHERE B.IXNAME = A.NAME AND A.UNIQUERULE <> 'D'
ORDER BY 1, 2, 5

Saludos, Antonio
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On