SQL Server ALTER DATABASE AUDIT produces a syntax error

acruukt9  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(88)

I'm trying to ADD CREATE and DROP commands to an existing SERVER AUDIT.

When executing the following statement :

ALTER DATABASE AUDIT SPECIFICATION Powercash_Audit
    FOR SERVER AUDIT PowercashAudit
    ADD (CREATE, DROP ON SCHEMA::dbo BY PUBLIC)
    WITH (STATE = ON);
GO

I've got the following error :

Msg 102, Level 15, State 1, Line 38
Incorrect syntax near 'CREATE'."

I didn't fix it yet, any ideas ?

Thanks in advance, Alex

h22fl7wq

h22fl7wq1#

In SQL Server, the CREATE and DROP actions cannot be directly added to a server-level audit specification. These actions are only applicable at the database level. Therefore, you need to modify your script to create a database-level audit specification and associate it with the desired server-level audit.

USE [YourDatabaseName];
CREATE DATABASE AUDIT SPECIFICATION Powercash_Audit
    FOR SERVER AUDIT PowercashAudit
    ADD (SCHEMA_OBJECT_CHANGE_GROUP)

USE [YourDatabaseName];
ALTER DATABASE AUDIT SPECIFICATION Powercash_Audit
    ADD (CREATE, DROP ON SCHEMA::dbo BY PUBLIC)
    WITH (STATE = ON);

相关问题