getIndexInfo Method (SQLServerDatabaseMetaData)

Download JDBC driver

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)  



A String that contains the catalog name.


A String that contains the schema name.


A String that contains the table name.


true if only indexes for unique values are returned. false if all indexes are returned.


true if the results reflect approximate or out-of-date values. false if the results are accurate.

Return Value

A SQLServerResultSet object.




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 int The number of rows in the table or unique values in the index.
PAGES int The number of pages used to store the index or table.
FILTER_CONDITION String The filter condition.

Note: SQL Server always returns null.


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


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 AdventureWorks2019 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( {  
         for (int i = 1; i <= cols; i++) {  
   catch (Exception e) {  

See Also

SQLServerDatabaseMetaData Methods
SQLServerDatabaseMetaData Members
SQLServerDatabaseMetaData Class