Created
April 23, 2016 20:04
-
-
Save bdcravens/06df30db6debf9b54b99ee49f330dcbf to your computer and use it in GitHub Desktop.
View table index fragmentation and rebuild index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT a.index_id, name, avg_fragmentation_in_percent | |
FROM sys.dm_db_index_physical_stats (DB_ID(N'my_db'), OBJECT_ID(N'dbo.my_table'), NULL, NULL, NULL) AS a | |
JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id; | |
ALTER INDEX idx_myIndex ON my_table | |
REBUILD WITH (FILLFACTOR = 80); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment