Need tsql to find index usage on views

Grossnickle, Brenda 80 Reputation points
2025-01-15T22:35:28+00:00

I have some views that have indexes and i want to get their usage - seeks, scan, lookups - but i cannot find the tsql code.

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
114 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 116.1K Reputation points MVP
    2025-01-15T22:41:25.01+00:00
    SELECT v.name, i.name, ius.*
    FROM  sys.dm_db_index_usage_stats ius
    JOIN   sys.views v ON ius.object_id = v.object_id
    JOIN  sys.indexes i ON ius.object_id = i.object_id
                       AND ius.index_id = i.index_id
    WHERE  ius.database_id = db_id()
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.