how to identify tables that are not being accessed by the application or used

NeophyteSQL 241 Reputation points
2021-03-05T20:41:18.373+00:00

how to identify unused tables on prod so they can be dropped if the table had index, will user updates column on the index usage stats give information what if the index never gets used and only non clustered indexes exist

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,759 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Guoxiong 8,126 Reputation points
    2021-03-05T22:21:24.497+00:00

    You may try to use the system view sys.dm_db_index_usage_stats to check the columns last_user_seek, last_user_scan, last_user_lookup and last_user_updates:

    SELECT o.name AS Table_Name, s.* 
    FROM sys.dm_db_index_usage_stats AS s
    INNER JOIN sys.databases AS d ON d.database_id = s.database_id
    INNER JOIN sys.objects AS o ON o.object_id = s.object_id
    WHERE d.name = 'DATABASE_NAME' AND o.type = 'U';
    

    Please note that the tracking data will be reset after the SQL server restarts.

    1 person found this answer helpful.
    0 comments No comments

  2. Cris Zhan-MSFT 6,606 Reputation points
    2021-03-08T09:32:39.247+00:00

    Hi,

    Please refer to the script in the following article.
    https://www.mssqltips.com/sqlservertip/4191/identify-unused-sql-server-tables/

    >will user updates column on the index usage stats give information what if the index never gets used and only non clustered indexes exist

    The system view sys.dm_db_index_usage_stats will returns counts of different types of index(HEAP,NONCLUSTERED, CLUSTERED)operations and the time each type of operation was last performed.