I need help from DB2 experts.My query is as follows:
I want to find out the column names for a particular indexe in a DB2 table.
Thanks in advance.
Regards
Apurba
I want to find out the column names for a particular indexe in a DB2 table.
Thanks in advance.
Regards
Apurba
Have a look at the SYSCAT.INDEXCOLUSE catalog view. It tells you which indexQuote:> I need help from DB2 experts.My query is as follows:
> I want to find out the column names for a particular indexe in a DB2 table.
SELECT colname
FROM syscat.indexcoluse
WHERE ( indschema, indname ) IN
( SELECT indschema, indname
FROM syscat.indexes
WHERE ( tabschema, tabname ) = ( ..., ...) )
ORDER BY colseq
If you are interested in the same for primary keys and unique constraints,
SYSCAT.KEYCOLUSE would be the catalog view of choice.
--
Knut Stolze
Information Integration
IBM Germany / University of Jena
I am not sure if you didn't notice that in syscat.indexes there a column
"colnames" which specifies all the column name on which index is defined on.
How about this:
SELECT indname, indschema, tabschema, tabname, colnames
FROM syscat.indexes
WHERE ( indname, indschema ) = (...., ....);
Cheers,
Jeegar
Quote:> Apurba wrote on Thursday 08 May 2003 09:33:
> > I need help from DB2 experts.My query is as follows:
> > I want to find out the column names for a particular indexe in a DB2
table.
> Have a look at the SYSCAT.INDEXCOLUSE catalog view. It tells you which
index
> is defined on which columns. And SYSCAT.INDEXES gives you the table name.
> SELECT colname
> FROM syscat.indexcoluse
> WHERE ( indschema, indname ) IN
> ( SELECT indschema, indname
> FROM syscat.indexes
> WHERE ( tabschema, tabname ) = ( ..., ...) )
> ORDER BY colseq
> If you are interested in the same for primary keys and unique constraints,
> SYSCAT.KEYCOLUSE would be the catalog view of choice.
> --
> Knut Stolze
> Information Integration
> IBM Germany / University of Jena
You are right, that is even simpler.Quote:> Hi Knut,
> I am not sure if you didn't notice that in syscat.indexes there a column
> "colnames" which specifies all the column name on which index is defined on.
> How about this:
> SELECT indname, indschema, tabschema, tabname, colnames
> FROM syscat.indexes
> WHERE ( indname, indschema ) = (...., ....);
--
Knut Stolze
Information Integration
IBM Germany / University of Jena
1) It doesn't show INCLUDE columns in the index.
2) It can be ambiguous. Consider the table T(FOO,BAR,FOO-BAR). The value
in SYSCAT.INDEXES.COLNAMES is "+FOO-BAR". What index is defined? Is it
(FOO ASC, BAR DESC) or is it ("FOO-BAR" ASC)?
--
_____________________________________________________________________
Doug Doole
DB2 Universal Database Development
IBM Toronto Labs
DB2 UDB v8.1 is available for AIX, HP, Linux, Solaris and Windows
http://www-3.ibm.com/software/data/db2/udb/v8/
Visit the DB2 UDB and DB2 Connect Online Support site at:
http://www.ibm.com/software/data/db2/udb/winos2unix/support
How aboutQuote:> Jeegar Ghodasara wrote on Thursday 08 May 2003 15:04:
> > Hi Knut,
> > I am not sure if you didn't notice that in syscat.indexes there a column
> > "colnames" which specifies all the column name on which index is defined on.
> > How about this:
> > SELECT indname, indschema, tabschema, tabname, colnames
> > FROM syscat.indexes
> > WHERE ( indname, indschema ) = (...., ....);
> You are right, that is even simpler.
:)
1. HELP: Finding index names in sysindexes using a column name
Hello and thanks in advance!!!
I need to find the name(s) of any index(es) which are on a column by using
the sysindexes table.
For example (psuedo SQL here....)
Select index_name from sysindexes where table_name = 'my_table' and
column_name = 'column_1'
etc...
Thanks....
2. Replicating the Data on remote SQL server.
3. How can if find all columns with an index on them
4. Strange Values in Float value.
5. Help finding which columns are indexes, primary keys etc using T-SQL (SysObjects/SysColumns tables)
6. Can I run the DTS Package from Query Analyzer
7. finding index and pk columns via ADOX
8. Tip: how to avoid database corruption
9. how do I find out column name on which a index is build
10. How to find descending columns in indexes !
11. FOUND VFP5.0 GRID BUG - Column not found error
12. ADP -- Can't Find column (column name)
13. Index name not found int the Index collection ??