How to use Trigger to monitor stored procedures in SQL Server
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.