Published on

December 15, 2022

Understanding SQL Server Indexes with INDEXPROPERTY

When working with SQL Server, it’s important to have a good understanding of indexes and how they can impact the performance of your database queries. In a previous tip, we discussed the DATABASEPROPERTYEX function, which allows you to retrieve information about various database properties. However, SQL Server also provides another useful built-in function called INDEXPROPERTY, which allows you to retrieve specific information about indexes.

The INDEXPROPERTY function can be called from a SELECT statement to return the results of one or more indexes. For example, if you want to find out the Index Fill Factor for all of the indexes in one of your databases, you can use the following query:

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'

This query will return the Index Fill Factor for each index in the specified database. The Index Fill Factor specifies the percentage of space on each leaf level page to be filled with data, leaving room for future growth. By analyzing the Index Fill Factor, you can determine if your indexes are properly optimized for your workload.

Here are some other useful information that you can retrieve using the INDEXPROPERTY function:

  • IndexDepth: Returns the number of levels the index has.
  • IsAutoStatistics: Indicates if the index was generated by the auto create statistics option.
  • IsClustered: Indicates if the index is clustered.
  • IsFulltextKey: Indicates if the index is the full-text key for a table.
  • IsHypothetical: Indicates if the index is hypothetical and cannot be used directly as a data access path.
  • IsPadIndex: Indicates if the index specifies space to leave open on each interior node.
  • IsPageLockDisallowed: Indicates if page locking is disallowed for the index.
  • IsRowLockDisallowed: Indicates if row locking is disallowed for the index.
  • IsStatistics: Indicates if the index was created by the CREATE STATISTICS statement or by the auto create statistics option.
  • IsUnique: Indicates if the index is unique.

By utilizing the INDEXPROPERTY function, you can gain valuable insights into the structure and properties of your indexes. This information can help you optimize your database performance and improve query execution times.

In conclusion, understanding SQL Server indexes and utilizing functions like INDEXPROPERTY can greatly enhance your ability to analyze and optimize your database performance. By retrieving specific information about your indexes, you can make informed decisions on how to best optimize your database for your workload.

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.