question

Hammy0607-2379 avatar image
0 Votes"
Hammy0607-2379 asked BertZhoumsft-7490 commented

SQL query sys.dm_db_index_usage_stats

I'm running the below SQL query. I know my database has over 500 tables but the query only returns stats on 288 tables. Why doesn't it return something for all the tables? Below is an example of what I'm running.

SELECT OBJECT_NAME(OBJECT_ID) AS [Table],
Last_user_update, Last_user_seek, Last_user_scan, Last_user_lookup
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID('table name')

sql-server-transact-sqlsql-server-reporting-servicessql-server-analysis-services
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@Hammy0607-2379

Do you have further question on this , could we offer more support?
If this helps on your issue, you could mark it as answer so other user with similar problem could see this easier. :)

Bert Zhou

0 Votes 0 ·
ErlandSommarskog avatar image
0 Votes"
ErlandSommarskog answered

When I ran that query in a database with 1800 tables on my server I did not get back a single row.

But that is not very strange - I have not executed any queries in this database since I restarted SQL Server.

So there you have it. Any table or index not listed in that query have not been read or written to since last time SQL Server was started. Or more precisely, since the database came online.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BertZhoumsft-7490 avatar image
0 Votes"
BertZhoumsft-7490 answered

Hi,@Hammy0607-2379

Welcome to Microsoft T-SQL Q&A Forum!

The phenomenon of not returning may of course occur , the count of index operations returned by sys.dm_db_index_usage_stats and the time of the last execution.

So, you need to check if there is really index maintenance on these tables , secondly , whenever you restart your database , it will make the counter empty , you can use the column in sys.dm_os_sys_infosqlserver_start_time to find the last database engine start time .

Finally, please refer to the official documentation which is well documented for these claims.


Best regards,
Bert Zhou


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.