我的查询sys.database_audit_specification不发回任何记录

时间:2019-05-25 05:04:50

标签: sql-server audit-logging

我正在研究SQL Server审核。我已经部署了服务器审核规范。现在,我想查询所有记录,但不返回任何内容。

我使用Windows Server 2012数据中心-SQL Server 2014开发人员版本

use master
go
select *
from sys.database_audit_specifications;
go

我没有输出,也不知道为什么。

我该如何解决?

Image

1 个答案:

答案 0 :(得分:0)

下面是一个示例,该示例创建服务器级审核,然后添加数据库级审核规范以跟踪dbo模式中任何对象的多项操作。

USE master;
GO

-- create aserver audit
CREATE SERVER AUDIT Test_Server_Audit 
  TO FILE ( FILEPATH = 'C:\temp\' ); -- you may need to change that'
GO

-- turn it on
ALTER SERVER AUDIT Test_Server_Audit WITH (STATE = ON);
GO

-- create a demo database    
CREATE DATABASE floob;
GO
USE floob;
GO
CREATE TABLE dbo.blat(x INT);
GO

-- create a database audit specification that monitors for activity
-- against any dbo object:
CREATE DATABASE AUDIT SPECIFICATION Test_Database_Audit
    FOR SERVER AUDIT Test_Server_Audit
    ADD (SELECT, UPDATE, DELETE, INSERT, EXECUTE ON SCHEMA::dbo BY PUBLIC)
    WITH (STATE = ON);
GO

-- do a couple of things:
SELECT * FROM dbo.blat;
DELETE dbo.blat;
GO

-- you should see those couple of things in the audit file:
SELECT * FROM sys.fn_get_audit_file('C:\temp\*.sqlaudit', NULL, NULL);
GO

要进一步阅读,请遵循this