SQL ServerIndexes
Fragmented indexes in the current database
Indexes over 30% fragmented and larger than 1,000 pages, where a rebuild is worth considering. LIMITED mode keeps the scan cheap.
Not yet verified. How scripts are tested
1SELECT OBJECT_SCHEMA_NAME(ips.object_id) AS schema_name,2 OBJECT_NAME(ips.object_id) AS table_name,3 i.name AS index_name, ips.index_type_desc,4 ips.avg_fragmentation_in_percent, ips.page_count5FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'LIMITED') ips6JOIN sys.indexes i ON i.object_id = ips.object_id AND i.index_id = ips.index_id7WHERE ips.avg_fragmentation_in_percent > 308 AND ips.page_count > 10009 AND i.name IS NOT NULL10ORDER BY ips.avg_fragmentation_in_percent DESC;Paste it into your query tool.
More SQL Server scripts: Indexes
- Missing index suggestionsThe optimizer's own index wish list, ranked by estimated benefit. Treat as leads, not instructions: overlapping suggestions are common.