问题描述
这个问题基本上是这个问题的延伸:
This question is basically an extension of this question:
如何判断数据库表是否正在被访问?想要像SELECT触发器"这样的东西
在作者在他的帖子中作为解决方案提供的查询中,我假设空值意味着自上次重新启动 SQL Server 以来没有访问过表.
In the query the author provided as a solution in his post, I assume a null value would mean that a table hasn't been accessed since the last time SQL Server was restarted.
我的问题是:有没有办法判断上次访问表的时间,如果上次访问是在上次 SQL 重新启动之前?另外,如何知道上次重新启动 SQL 的时间?
My question is: Is there a way to tell when a table was last accessed, if the last access was before the last time SQL restarted? Also, how can I tell when the last time SQL was restarted?
推荐答案
对于SQL Server 2008中的sql server启动时间,
For sql server start time in SQL Server 2008,
select sqlserver_start_time from sys.dm_os_sys_info
对于服务器重启后的最后一次用户访问,
For last user access since server restart,
select DB_NAME(us.[database_id]) as [db], OBJECT_NAME(us.[object_id], us.[database_id]) as [object],
MAX(us.[last_user_lookup]) as [last_user_lookup], MAX(us.[last_user_scan]) as [last_user_scan], MAX(us.[last_user_seek]) as [last_user_seek]
from sys.dm_db_index_usage_stats as us
where us.[database_id] = DB_ID() AND us.[object_id] = OBJECT_ID('tblname')
group by us.[database_id], us.[object_id];
我每天都记录这个表,所以我在重新启动后有它.在它们被删除后,它还可以作为索引审计.
I log this table daily so I have it after restarts. It can also act as an index audit after they have been dropped.
这篇关于如何判断上次访问 sql 表的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!