Cómo crear una auditoría de base de datos
Antes de poder crear una especificación de auditoría de base de datos, deberá crear y configurar un objeto SQL Server Audit que se pueda usar en la auditoría.
Para realizar esta tarea debe usar el Editor de consultas de SQL Server Management Studio con objeto de llevar a cabo el siguiente procedimiento. En el ejemplo siguiente se crea una auditoría de base de datos de cualquier operación de inserción en la base de datos AdventureWorks2008R2 de la tabla Person.Person y se envían los resultados al registro de eventos de aplicación de Windows.
Crear una auditoría de base de datos
Cree un objeto Audit y defina el destino.
/* Create the SQL Server Audit object, and send the results to the Windows Application event log. */ CREATE SERVER AUDIT Test_SQL_Server_Audit TO APPLICATION_LOG /* The Queue Delay is set to 1000, meaning one second intervals to write to the target. */ WITH ( QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE); GO;Cree la especificación de auditoría de base de datos y asígnela al objeto Audit.
/* Create the Database Audit Specification object using an Audit event for the Person.Person Table and the FirstName and LastName columns. */ USE AdventureWorks2008R2; GO; CREATE DATABASE AUDIT SPECIFICATION Test_Database_Audit_Specification FOR SERVER AUDIT Test_SQL_Server_Audit ADD (INSERT ON Person.Person BY dbo) WITH (STATE = ON); GOHabilite la auditoría.
/* Enable the audit. */ ALTER SERVER AUDIT Test_SQL_Server_Audit WITH (STATE = ON); GO