Thursday, January 5, 2023

SQL Server: When was table last updated and other usage stats

Tables:

select 
tbl.name

,ius.last_user_update

,ius.user_updates

--,ius.last_user_seek

--,ius.last_user_scan

--,ius.last_user_lookup

--,ius.user_seeks

--,ius.user_scans

--,ius.user_lookups

,tbl.create_date

,tbl.modify_date

FROM

sys.dm_db_index_usage_stats ius INNER JOIN

sys.tables tbl ON (tbl.OBJECT_ID = ius.OBJECT_ID)

WHERE ius.database_id = DB_ID()

--ORDER BY tbl.name

ORDER BY ius.last_user_update desc



Views:

SELECT

        [name]

       ,create_date

       ,modify_date

FROM

        sys.views


UDF (User Defined Functions):

select * from sys.objects where type in ('FN', 'IF', 'TF')
and name = ...............

NOTE: TF, for example, is a Table-valued Function.

 

              order by modify_date desc