Sql Server DMV --- log of object use?

DMVs have tons of great info but what I am looking for is simple -- how frequently is a table, query, proc touched or run?  When was the last time, first time, etc.  What DMV  (or any other tool) can show me this?  Seeing last time Exec plan was run is not accurate, because exec  plan can be refreshed.
Hec RamseyAsked:
Who is Participating?
 
lcohanDatabase AnalystCommented:
You can use dm_exec_query_stats to get info about any query executed since last plan was cached:
https://msdn.microsoft.com/en-us/library/ms189741.aspx

 SELECT pa.value AS dbid,
        COALESCE(DB_NAME(st.dbid),
                 DB_NAME(CAST(pa.value as int))+'*',
                 'Resource') AS DBNAME,
        SUBSTRING(text,
         -- starting value for substring
         CASE WHEN statement_start_offset = 0
              OR statement_start_offset IS NULL
                THEN 1
                ELSE statement_start_offset/2 + 1 END,
         -- ending value for substring
         CASE WHEN statement_end_offset = 0
           OR statement_end_offset = -1
           OR statement_end_offset IS NULL
                THEN LEN(text)
                ELSE statement_end_offset/2 END -
                CASE WHEN statement_start_offset = 0
                           OR statement_start_offset IS NULL
                                THEN 1
                                ELSE statement_start_offset/2  END + 1
         )  AS TSQL,
         *
 FROM sys.dm_exec_query_stats  
    CROSS APPLY sys.dm_exec_sql_text(sql_handle) st
    OUTER APPLY sys.dm_exec_plan_attributes(plan_handle) pa
     WHERE attribute = 'dbid'
0
 
Scott PletcherSenior DBACommented:
SQL doesn't capture that info.  You would need to set up something to capture that info if you need it.
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
No way to have that information unless you create an audit system and store all captured data in a database for later use.
0
 
Hec RamseyAuthor Commented:
thanks!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.