SQL Server audit infrastructure for INSERT, UPDATE and DELETE.
- A centralised audit table,
- Supports up to three columns for composite primary key,
- No need to modify triggers if new columns are added or existing ones are deleted,
- Work against >= SQL 2008 and SQL Azure.
- Only support column types that are compatible with sql_variant (https://docs.microsoft.com/en-us/sql/t-sql/data-types/sql-variant-transact-sql),
- May not be suitable for high traffic CUD database.
- Tables:
- dbo.Logs,
- Stored procedures:
- dbo.CreateLog
- dbo.CreateLogTriggerForInsert
- dbo.CreateLogTriggerForUpdate
- dbo.CreateLogTriggerForDelete
- Use DROP TRIGGER or DISABLE TRIGGER manually to uninstall them.
- Audit table name is dbo.Logs,
- Trigger name starts with TRI_Logs__TableName for INSERT, TRU_Logs__TableName for UPDATE and TRD_Logs__TableName for DELETE,
- All the triggers are set to run as first trigger (https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-settriggerorder-transact-sql),
- As with other DML triggers, it is wise to disable them when performing import such as BULK INSERT for example.
EXECUTE dbo.CreateLogTriggerForInsert @SchemaName = N'dbo', @TableName = N'Birds';
EXECUTE dbo.CreateLogTriggerForUpdate @SchemaName = N'dbo', @TableName = N'Birds';
EXECUTE dbo.CreateLogTriggerForDelete @SchemaName = N'dbo', @TableName = N'Birds';