SQL Server中使用Trigger监控存储过程更改脚本实例
下面的Trigger用于监控存储过程的更改。
创建监控表:
CREATE TABLE AuditStoredProcedures( DatabaseName sysname , ObjectName sysname , LoginName sysname , ChangeDate datetime , EventType sysname , EventDataXml xml );
创建监控Trigger:
CREATE TRIGGER dbtAuditStoredProcedures ON DATABASE FOR CREATE_PROCEDURE, ALTER_PROCEDURE, DROP_PROCEDURE AS 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 );
相关推荐
Chriswang 2020-04-30
donghongbz 2020-01-18
leonranri 2016-12-09
workflow 2013-08-15
stingfire 2012-05-16
itwxming 2015-09-02
周健华 2019-06-28
donghongbz 2011-10-12
去山中嘘嘘 2015-01-21
Awara 2019-06-27
小肖 2014-05-19
mxcsdn 2010-10-20
adeyi 2019-06-21
咸鱼 2012-10-28
greensomnuss 2012-10-09
Gcalolin 2019-06-20
愚盦 2011-05-24
每天积累一点点 2011-03-08
Lucianoesu 2018-10-27