How to find last time a table was used in SQL Server Database

Use this SQL to find the last time a tables was used in SQL Server Database.

SELECT
    DB_NAME(ius.[database_id])   AS [Database],
    OBJECT_NAME(ius.[object_id]) AS [TableName],
    MAX(ius.[last_user_lookup])  AS [last_user_lookup],
    MAX(ius.[last_user_scan])    AS [last_user_scan],
    MAX(ius.[last_user_seek])    AS [last_user_seek]
FROM
    sys.dm_db_index_usage_stats AS ius
WHERE
    ius.[database_id] = DB_ID()
AND ius.[object_id] = OBJECT_ID('YourTableName')
GROUP BY
    ius.[database_id],
    ius.[object_id];
Note: the DMV will get reset when database services or servers are restart.


Leave a comment or a question in the comment area bellow if you fell like


Be a sport and

Search

Loading... Please wait

Subscribe to our Newsletter

Be a sport and

x