Quantcast
Channel: Geekswithblogs.net
Viewing all articles
Browse latest Browse all 6441

SQL Server - index usage/utilization stats

$
0
0
Goal:
Find out what indexes are being used, if at all, and if the stats on seeks, scans and lookups on the indexes:
index-seek (preferred)
index-scan (worst)
index-lookup

Solution:

Run this scrip against your database

SELECT

o.name AS object_name,

i.name AS NameOfIndex,

i.type_desc as IsItClustered,

u.user_seeks as IndexSeeks, u.user_scans as IndexScans,

u.user_lookups as IndexLookups, u.user_updates as HowManyUpdates,

o.type

FROM

sys.indexes i

JOIN

sys.objects o ON i.object_id = o.object_id

LEFT JOIN

sys.dm_db_index_usage_stats u ON i.object_id = u.OBJECT_ID

AND i.index_id = u.index_id

AND u.database_id = DB_ID()

WHERE

o.type IN ('U', 'V') AND

i.name IS NOT NULL

ORDER BY

o.name, i.name

Viewing all articles
Browse latest Browse all 6441