SQL Server中應用Trigger監控存儲進程更改劇本實例。本站提示廣大學習愛好者:(SQL Server中應用Trigger監控存儲進程更改劇本實例)文章只能為提供參考,不一定能成為您想要的結果。以下是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 );