Retrieving SQL Server Index Properties with INDEXPROPERTY

Problem

SQL Server has several functions to assist with meta data about the server, databases, indexes, and more. In this tip, we will look at how to get index information for indexes in a database using the INDEXPROPERTY function.

Solution

SQL Server has a built-in function called INDEXPROPERTY that allows you to return specific information about an index. This function can be called from a SELECT statement to return the results of one or more indexes.

Example Use of INDEXPROPERTY function

So to find out the Index Fill Factor for all of your indexes in one of your databases you can run the following query. The table below shows sample output from this query when issued against a database.

SELECT sysobjects.name,  
       sysindexes.name,  
       INDEXPROPERTY(OBJECT_ID(sysobjects.name),sysindexes.name,'IndexFillFactor')
FROM   sysobjects INNER JOIN  
       sysindexes ON sysobjects.id = sysindexes.id 
WHERE  xtype = 'U' 
TableIndexIndexFillFactor
OrdersCustomerID80
OrdersCustomersOrders80
OrdersEmployeeID80
OrdersEmployeesOrders80
OrdersOrderDate80
OrdersShippedDate80
OrdersShippersOrders80
OrdersShipPostalCode80
ProductsPK_Products80
ProductsCategoriesProducts80
ProductsCategoryID80
ProductsProductName80
ProductsSupplierID80
ProductsSuppliersProducts80

INDEXPROPERTY Function Options

Above we used IndexFillFactor, below you can see all of the other properties you can return from this function.

PropertyDescription
IndexDepthDepth of the index.
Returns the number of levels the index has.
IndexFillFactorIndex specifies its own fill factor.
Returns the fill factor used when the index was created or last rebuilt.
IndexIDIndex ID of the index on a specified table or indexed view.
IsAutoStatisticsIndex was generated by the auto create statistics option of sp_dboption.
1 = True
0 = False
NULL = Invalid input
IsClusteredIndex is clustered.
1 = True
0 = False
NULL = Invalid input
IsDisabledIndex is disabled.
IsFulltextKeyIndex is the full-text key for a table.
1 = True
0 = False
NULL = Invalid input
IsHypotheticalIndex is hypothetical and cannot be used directly as a data access
path. Hypothetical indexes hold column level statistics.
1 = True
0 = False
NULL = Invalid input
IsPadIndexIndex specifies space to leave open on each interior node.
1 = True
0 = False
NULL = Invalid input
IsPageLockDisallowed1 = Page locking is disallowed through sp_indexoption.
0 = Page
locking is allowed.
NULL = Invalid input
IsRowLockDisallowed1 = Row locking is disallowed through sp_indexoption.
0 = Row
locking is allowed.
NULL = Invalid input.
IsStatisticsIndex was created by the CREATE STATISTICS statement or by the auto
create statistics option of sp_dboption. Statistics indexes are used
as a placeholder for column-level statistics.
1 = True
0 = False
NULL = Invalid input
IsUniqueIndex is unique.
1 = True
0 = False
NULL = Invalid input
IsColumnstoreIndex is a columnstore index
IsOptimizedForSequentialKeyIndex has optimization for last-page inserts enabled.

Next Steps

  • Take a look at this built-in index property function and how you can use it to document your databases or easily find out the index settings in your databases
  • Use this function to audit your databases to see what the index settings are
  • Use this along with this stored procedure to fully document your database indexes
  • Read this tip about the built-in function DATABASEPROPERTYEX to get database properties.

Leave a Reply

Your email address will not be published. Required fields are marked *