Created
May 20, 2015 22:02
-
-
Save srkirkland/0797c0b2ba9d9c53a558 to your computer and use it in GitHub Desktop.
helpful rebuild your indexes script
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 name, OBJECT_NAME(a.object_id), avg_fragmentation_in_percent, | |
'ALTER INDEX ' + b.name + ' ON ' + OBJECT_NAME(a.object_id) +' REBUILD WITH (STATISTICS_NORECOMPUTE = ON)' as command | |
FROM sys.dm_db_index_physical_stats ( | |
DB_ID(N'PrePurchasing') | |
, OBJECT_ID('PrePurchasing') | |
, NULL | |
, NULL | |
, NULL) AS a | |
JOIN sys.indexes AS b | |
ON a.object_id = b.object_id AND a.index_id = b.index_id | |
order by avg_fragmentation_in_percent desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment