Forked from samirbehara-zz/Identifying Unused Indexes in SQL Server
Created
November 16, 2017 02:21
-
-
Save tangdf/bf41adb209c1a8aaf7e31a56019d1848 to your computer and use it in GitHub Desktop.
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
-- Identifying Unused Indexes in SQL Server | |
SELECT OBJECT_NAME(s.[object_id]) AS [Table Name] , | |
i.name AS [Index Name] , | |
i.fill_factor , | |
user_updates AS [Total Writes] , | |
user_seeks + user_scans + user_lookups AS [Total Reads] , | |
user_updates - ( user_seeks + user_scans + user_lookups ) AS [Difference] | |
FROM sys.dm_db_index_usage_stats AS s WITH ( NOLOCK ) | |
INNER JOIN sys.indexes AS i WITH ( NOLOCK ) ON s.[object_id] = i.[object_id] | |
AND i.index_id = s.index_id | |
WHERE OBJECTPROPERTY(s.[object_id], 'IsUserTable') = 1 | |
AND s.database_id = DB_ID() | |
AND user_updates > ( user_seeks + user_scans + user_lookups ) | |
AND i.index_id > 1 | |
ORDER BY [Difference] DESC , | |
[Total Writes] DESC , | |
[Total Reads] ASC | |
OPTION ( RECOMPILE ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment