-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Expand CommandLog with Auditing Columns.sql
- Loading branch information
1 parent
626b0ae
commit 3c8e648
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Database Maintenance Plans/Expand CommandLog with Auditing Columns.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Expanding CommandLog with auditing columns | ||
========================================== | ||
Author: Eitan Blumin | https://madeiradata.com | ||
Date: 2024-02-14 | ||
Description: | ||
Use this script to add several auditing columns to | ||
the CommandLog table for Ola Hallengren's Maintenance Solution. | ||
These columns can be used to identify the processes that perform | ||
maintenance operations using Ola's framework. | ||
*/ | ||
GO | ||
CREATE OR ALTER FUNCTION dbo.GetCurrentInputBuffer() | ||
RETURNS nvarchar(max) | ||
AS | ||
BEGIN | ||
RETURN (SELECT TOP(1) event_info FROM sys.dm_exec_input_buffer(@@SPID,NULL)) | ||
END | ||
GO | ||
ALTER TABLE [dbo].[CommandLog] ADD | ||
[Hostname] [sysname] COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT DF_CommandLog_Hostname DEFAULT(HOST_NAME()), | ||
[HostPID] [int] NULL DEFAULT(HOST_ID()), | ||
[AppName] [sysname] COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT DF_CommandLog_AppName DEFAULT(APP_NAME()), | ||
[LoginName] [sysname] COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT DF_CommandLog_LoginName DEFAULT(SUSER_SNAME()), | ||
[SPID] [int] NULL CONSTRAINT DF_CommandLog_SPID DEFAULT(@@SPID), | ||
[InputBuffer] nvarchar(max) CONSTRAINT DF_CommandLog_InputBuffer DEFAULT(dbo.GetCurrentInputBuffer()), | ||
[IPAddress] [sysname] COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT DF_CommandLog_IPAddress DEFAULT(CONVERT(sysname, CONNECTIONPROPERTY('client_net_address'))) | ||
GO |