Getting last user update time for all tables in a

2019-08-23 11:15发布

In SQL SERVER 2008 R2 I have 7 databases, each one with around 1000 tables.

I need to know wich tables were last updated by users. With some research I got to this code:

SELECT  OBJECT_NAME(OBJECT_ID) AS TableName,
                                  last_user_update,
                                  user_updates,
                                  index_id
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID('SP3D_DB_RESEARCH_MDB') AND 
                    OBJECT_ID = OBJECT_ID('CORECone3d')
GO

This returns only one result, since it's asking for last user updates on a specific table/database.

Is there any way to put it in some sort of loop so it iterate through all tables in a database and I can get which tables were last modified?

It does not have to be a query as result, it could be a simple text output.

I don't know if this matters, but I'm using MS SQL SERVER MANAGEMENT STUDIO.

  • UPDATE -

Based on Pradeep answer I get the following results, with TableName NULL

query results based on answer

1条回答
Emotional °昔
2楼-- · 2019-08-23 11:42

Try this:

SELECT  OBJECT_NAME(OBJECT_ID) AS TableName,
                              last_user_update,
                              user_updates,
                              index_id
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID('SP3D_DB_RESEARCH_MDB')
查看更多
登录 后发表回答