日期:2014-05-17 浏览次数:20618 次
USE master;注意,路径需要修改,temp文件夹也要实现开启。
GO
CREATE SERVER AUDIT ServerAudit
TO FILE (FILEPATH = 'E:\temp\', MAXSIZE = 1 GB)--注意更改文件路径
WITH (ON_FAILURE = CONTINUE);
GO
ALTER SERVER AUDIT ServerAudit
WITH (STATE = ON);
USE AdventureWorks;
GO
CREATE DATABASE AUDIT SPECIFICATION schema_change
FOR SERVER AUDIT ServerAudit
ADD (SCHEMA_OBJECT_CHANGE_GROUP)
WITH (STATE = ON);
GO
CREATE TABLE dbo.splunge ( id INT ) ;
GO
CREATE TRIGGER dbo.splunge_trigger ON dbo.splunge
FOR INSERT
AS
BEGIN
SELECT 1 ;
END
GO
SELECT event_time ,
succeeded ,
server_principal_name ,
[object_name] ,
[statement]
FROM sys.fn_get_audit_file('E:\Temp\ServerAudit*', NULL, NULL)
WHERE database_name = 'AdventureWorks' ;
DISABLE TRIGGER dbo.splunge_trigger ON dbo.splunge;如果你重新启用这个触发器,你会再看到另外一行,如果觉得返回数据太多,可以在where语句中添加筛选:
GO
SELECT event_time ,
succeeded ,
server_principal_name ,
[object_name] ,
[statement]
FROM sys.fn_get_audit_file('E:\Temp\ServerAudit*', NULL, NULL)
WHERE database_name = 'AdventureWorks' ;
AND [statement] LIKE '%disable%trigger%'