Skip to content

Instantly share code, notes, and snippets.

@mephistoc
Created December 16, 2021 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mephistoc/bdc5e3dab8f3239b52a31fb5d569be41 to your computer and use it in GitHub Desktop.
Save mephistoc/bdc5e3dab8f3239b52a31fb5d569be41 to your computer and use it in GitHub Desktop.
SELECT OBJECT_NAME(dt.object_id) as [TableName] , --資料表名稱
si.name as [IndexName] , --索引名稱
dt.avg_fragmentation_in_percent, --邏輯片段的百分比 (索引中失序的頁面)。
dt.avg_page_space_used_in_percent
FROM
(SELECT object_id ,
index_id ,
avg_fragmentation_in_percent,
avg_page_space_used_in_percent
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, 'DETAILED')
WHERE index_id <> 0
) AS dt --does not return information about heaps
INNER JOIN sys.indexes si
ON si.object_id = dt.object_id
AND si.index_id = dt.index_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment