Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use Trigger to monitor stored procedures in SQL Server

Shulou Source: shulou.com Published: 2022-05-31 19:33:34 10月04日 Update

This article will explain in detail how to use Trigger to monitor stored procedures in SQL Server. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Create a monitoring table:

CREATE TABLE AuditStoredProcedures (DatabaseName sysname, ObjectName sysname, LoginName sysname, ChangeDate datetime, EventType sysname, EventDataXml xml)

Create a monitoring Trigger:

CREATE TRIGGER dbtAuditStoredProceduresON DATABASEFOR CREATE_PROCEDURE, ALTER_PROCEDURE, DROP_PROCEDUREAS DECLARE @ eventdata XML;SET @ eventdata = EVENTDATA () INSERT INTOAuditStoredProcedures (DatabaseName,ObjectName,LoginName,ChangeDate,EventType,EventDataXml) VALUES (@ eventdata.value ('(/ EVENT_INSTANCE/DatabaseName) [1]', 'sysname'), @ eventdata.value (' (/ EVENT_INSTANCE/ObjectName) [1]', 'sysname'), @ eventdata.value (' (/ EVENT_INSTANCE/LoginName) [1]', 'sysname'), GETDATE (), @ eventdata.value (' (/ EVENT_INSTANCE/EventType) [1]', 'sysname'), @ eventdata)) On how to use Trigger in SQL Server to monitor stored procedures is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Monitoring process storage content articles more knowledge articles good quality reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Xiaomi MySQL Apple Microsoft