The query:
SELECT
name AS TableName,
create_date AS CreatedDate,
modify_date as ModifyDate
FROM sys.tables
order by ModifyDate;
...will tell me the last time a table was created and modified (from a DDL perspective). But I want to know the last time actual data was either inserted or removed from the table. Is it possible to get this in SQL Server?
sys.tables. I'll remove it. For the second query joining can have some benefits compared to callingobject_name- same as any join can perform better than encapsulating a query in a non inlined scalar UDF and calling that. The function has its own overhead and this approach also forces a nested loops approach. Metadata functions such asobject_namealso don't respect the isolation level of the outer query so you might want to avoid them if using read uncommitted to avoid blocking – Martin Smith Nov 30 '21 at 15:37