I did not find any similar question here, so please direct me if I'm wrong.
I have a large database (inherited from former employee) and I need to clean up that database.
How do I find all tables and views which are not used at all in database?
I found a query at SQL Server script to know when the table accessed last time (CALSQL | SQL Server Community Blog):
with cte_recent as ( select SCHEMA_NAME(B.schema_id) +'.'+object_name(b.object_id) as tbl_name, (select MAX(last_user_dt) from (values (last_user_seek),(last_user_scan),(last_user_lookup)) as all_val(last_user_dt)) as access_datetime FROM sys.dm_db_index_usage_stats a right outer join sys.tables b on a.object_id = b.object_id ) select tbl_name,max(access_datetime) as recent_datetime from cte_recent group by tbl_name order by recent_datetime desc , 1