您的位置:首页 > 博客中心 > 数据库 >

SQL Server 默认跟踪应用3 -- 检测对表的DDL操作

时间:2022-03-14 02:59

SQL Server 默认跟踪应用3 -- 检测对表的DDL操作


在SQL Server数据库上发生的DDL操作,能知道是谁做的么?

 

是的。SQL Server默认跟踪有对象修改事件。

这个脚本列出所有的对象修改事件。查询条件中加上时间和数据库名的限制。

 

select e.name as eventclass,
t.loginname,
t.spid,
t.starttime,
t.textdata,
t.objectid,
t.objectname,
t.databasename,
t.hostname,
t.ntusername,
t.ntdomainname,
t.clientprocessid,
t.applicationname,
t.error
FROM sys.fn_trace_gettable(CONVERT(VARCHAR(150), ( SELECT TOP 1f.[value]
FROM sys.fn_trace_getinfo(NULL) f WHERE f.property = 2)), DEFAULT) T
inner join sys.trace_events e on t.eventclass = e.trace_event_id
where eventclass=164

 

本文出自 “” 博客,请务必保留此出处

热门排行

今日推荐

热门手游