Retrieves a description of the indexes and statistics for the given table.

public java.sql.ResultSet getIndexInfo(java.lang.String cat,
                                       java.lang.String schema,
                                       java.lang.String table,
                                       boolean unique,
                                       boolean approximate)

Parameters

cat

A string that contains the catalog name.

schema

A string that contains the schema name.

table

A string that contains the table name.

unique

True if only indexes for unique values are returned. False if all indexes are returned.

approximate

True if the results reflect approximate or out-of-date values. False if the results are accurate.

Return Value

A SQLServerResultSet object.

Exceptions

SQLServerException

Remarks

This getIndexInfo method is specified by the getIndexInfo method in the java.sql.DatabaseMetaData interface.

The result set returned by the getIndexInfo method will contain the following information:

Name Type Description

TABLE_CAT

string

The name of the database in which the specified table resides.

TABLE_SCHEM

string

The schema for the table.

TABLE_NAME

string

The name of the table.

NON_UNIQUE

boolean

Indicates whether the index values can be non-unique.

INDEX_QUALIFIER

string

The name of the index owner. It will be null when TYPE is tableIndexStatistic.

INDEX_NAME

string

The name of the index.

TYPE

short

The type of the index. It can be one of the following values:

tableIndexStatistic (0)

tableIndexClustered (1)

tableIndexHashed (2)

tableIndexOther (3)

ORDINAL_POSITION

short

The ordinal position of the column in the index. The first column in the index is 1.

COLUMN_NAME

string

The name of the column.

ASC_OR_DESC

string

The order used in the collation of the index. It can be one of the following values:

A (ascending)

D (descending)

NULL (not applicable)

Note: SQL Server always returns "A".

CARDINALITY

integer

The number of rows in the table or unique values in the index.

PAGES

integer

The number of pages used to store the index or table.

FILTER_CONDITION

string

The filter condition.

Note: SQL Server always returns null.

Note: For more information about the data returned by the getIndexInfo method, see "sp_indexes (Transact-SQL)" in SQL Server Books Online.

Example

The following example demonstrates how to use the getIndexInfo method to return information about the indexes and statistics of the Person.Contact table in the SQL Server 2005 AdventureWorks sample database.

public static void executeGetIndexInfo(Connection con) {
   try {
      DatabaseMetaData dbmd = con.getMetaData();
      ResultSet rs = dbmd.getIndexInfo("AdventureWorks", "Person", "Contact", false, true);
      ResultSetMetaData rsmd = rs.getMetaData();

      // Display the result set data.
      int cols = rsmd.getColumnCount();
      while(rs.next()) {
         for (int i = 1; i <= cols; i++) {
            System.out.println(rs.getString(i));
         }
      }
      rs.close();
   } 

   catch (Exception e) {
      e.printStackTrace();
   }
}

See Also