12

Is there any way to tell from within a trigger, when it gets fired, that it is being fired as the result of a DML action that occurred within another specific trigger?

Any chance any information about the call stack is exposed in the EVENTDATA() function? Or another function? I'd prefer not having to shred XML. 🙂

I'm ideally shooting for getting the name of the original trigger that executed the DML that caused the second trigger to fire, from within the scope of that second trigger. But I'm open to similar ways of identifying the source too.

I have full control over the code of both triggers in question.

0

1 Answer 1

15

You can use TRIGGER_NESTLEVEL with an objectid parameter

IF TRIGGER_NESTLEVEL(OBJECT_ID(N'dbo.OtherTrigger', 'TR')) > 0
BEGIN
    -- do stuff
END;

The EVENTDATA() function is only relevant for DDL triggers anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.