Script: Check Index Fragmentation Across All Databases

This script checks index fragmentation levels across all online databases on the instance. It helps identify heavily fragmented indexes that may require maintenance.

This is useful when reviewing index health, validating maintenance jobs, or troubleshooting performance issues related to inefficient index access.


The Script


Example Output

The result set shows indexes across all user databases, including fragmentation percentage and page count. Larger indexes with higher fragmentation appear at the top.

This allows you to quickly identify indexes that may benefit from rebuild or reorganise operations.

SQL Server query showing index fragmentation across all databases

Notes

  • Uses LIMITED scan mode for reduced overhead
  • Excludes very small indexes (page_count > 100)
  • High fragmentation on large indexes may impact range scans
  • Intended for validation and investigation, not automatic maintenance

Comments

Leave a Reply

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