繁体   English   中英

您如何找到最后一个访问数据库的用户以及该访问的时间戳?

[英]How do you find the last user to access a database and the timestamp of that access?

我在 Windows Server 2003 机器上有一个 SQL Server 2005 数据库(是的,我们正在尝试迁移到更新的机器)。 我可以使用以下代码查看上次访问各种数据库的时间:

select 
    d.name, 
    x1 = (select X1 = max(bb.xx) 
          from 
              (select xx = max(last_user_seek) 
               where max(last_user_seek) is not null 
          union all 
          select xx = max(last_user_scan) 
          where max(last_user_scan) is not null 
          union all 
          select xx = max(last_user_lookup) 
          where max(last_user_lookup) is not null 
          union all 
          select xx = max(last_user_update) 
          where max(last_user_update) is not null) bb) 
from
    master.dbo.sysdatabases d 
left outer join 
    sys.dm_db_index_usage_stats s on d.dbid= s.database_id 
group by 
    d.name

这很好用,但我需要找出哪个用户执行了该访问。 我该怎么做?

您需要打开数据库审计。 您应该能够以管理员的责任来执行此操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM