1. 程式人生 > >princelintb的專欄

princelintb的專欄

DROP TRIGGER LogTrigger ON DATABASE
GO
CREATE TRIGGER LogTrigger 
ON DATABASE
FOR CREATE_TABLE, ALTER_TABLE ,DROP_TABLE, --table
CREATE_CONTRACT,DROP_CONTRACT,--constraint
CREATE_INDEX,ALTER_INDEX,DROP_INDEX,--index
CREATE_VIEW,ALTER_VIEW,DROP_VIEW,--view
CREATE_PROCEDURE,ALTER_PROCEDURE,DROP_PROCEDURE,--procedure
CREATE_FUNCTION,ALTER_FUNCTION,DROP_FUNCTION,--function
CREATE_TRIGGER,ALTER_TRIGGER,DROP_TRIGGER --trigger
AS
DECLARE @data XML
SET @data = EVENTDATA()
INSERT LogTable 
   (DB_User, EventType, SQLString,ChangeTime) 
   VALUES
   (CONVERT(VARCHAR(100), CURRENT_USER), 
   @data.value('(/EVENT_INSTANCE/EventType)[1]', 'VARCHAR(100)'), 
   @data.value('(/EVENT_INSTANCE/TSQLCommand)[1]', 'VARCHAR(2000)'),
   GETDATE()
    ) ;
GO