Created
February 15, 2024 13:43
-
-
Save pfrozi/3620111d23e21eec14183fc9d7fd8b5c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
DB_NAME() AS DatbaseName | |
, SCHEMA_NAME(o.Schema_ID) AS SchemaName | |
, OBJECT_NAME(s.[object_id]) AS TableName | |
, i.name AS IndexName | |
, ROUND(avg_fragmentation_in_percent,2) AS [Fragmentation %] | |
FROM sys.dm_db_index_physical_stats(db_id(),null, null, null, null) s | |
INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id] | |
AND s.index_id = i.index_id | |
INNER JOIN sys.objects o ON i.object_id = O.object_id | |
WHERE s.database_id = DB_ID() | |
AND i.name IS NOT NULL AND OBJECTPROPERTY(s.[object_id], 'IsMsShipped') = 0 | |
ORDER BY [Fragmentation %] DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment