Skip to content

Instantly share code, notes, and snippets.

@aviatrix
Created October 22, 2019 17:50
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 aviatrix/b96a47c7acecf0df7e4221b599b1f3cf to your computer and use it in GitHub Desktop.
Save aviatrix/b96a47c7acecf0df7e4221b599b1f3cf to your computer and use it in GitHub Desktop.
USE AdventureWorks2012;
GO
-- Find the average fragmentation percentage of all indexes
-- in the HumanResources.Employee table.
SELECT a.index_id, name, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (DB_ID(N'AdventureWorks2012'),
OBJECT_ID(N'HumanResources.Employee'), NULL, NULL, NULL) AS a
JOIN sys.indexes AS b
ON a.object_id = b.object_id AND a.index_id = b.index_id;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment