Question

I have a database trigger that logs DDL changes. It has the folowing format

CREATE TRIGGER [Log_DDL_Changes]

ON DATABASE
FOR 
CREATE_TABLE, ALTER_TABLE, DROP_TABLE, 
CREATE_INDEX, ALTER_INDEX, DROP_INDEX, 
CREATE_PROCEDURE, ALTER_PROCEDURE, DROP_PROCEDURE,
CREATE_VIEW, ALTER_VIEW, DROP_VIEW,
CREATE_FUNCTION, ALTER_FUNCTION, DROP_FUNCTION, RENAME

--Fires only for CREATE / ALTER / DROP Table and PROCs
AS 

BEGIN
.
.
.
END

I'd like to add special handling whenever a table, view or index is created or changed.

How can I determine which event triggered the trigger for a TRIGGER that handles multiple events?

Was it helpful?

Solution

You use something like this in your trigger:

SELECT EVENTDATA().value('(/EVENT_INSTANCE/EventType)[1]','nvarchar(max)')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top