sql - 您如何找到最后一个访问数据库的用户以及该访问的时间戳?
问题描述
我在 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
这很好用,但我需要找出哪个用户执行了该访问。我该怎么做?
解决方案
您需要打开数据库审计。您应该能够以管理员的责任来执行此操作。
推荐阅读
- r - R:如何选择列的子集并在多列上重复此操作
- typescript - 打字稿在函数类型声明中预期'=>'
- pytorch - torch_scatter 的问题:未定义的符号
- python - 使用 Ising 模型寻找时间相关的平衡情况
- android - 工具栏/顶部栏/操作栏中的 Android Studio xml 问题
- javascript - 在带有 javascript 或其他方式的闪亮应用程序中使用鼠标即时调整 DT::datatable() 列大小
- php - Woocommerce 在结帐时禁用运输选项方法
- python - QVideoWidget 内容未从小部件中获取
- python - 使用 python webdriver 打印不是常规字符串的元素
- r - 对范围为 [0, 1] 的变量进行对数转换