Possible Duplicate:
Is it possible for a trigger to find the name of the stored procedure that modified data?
I have a table with a trigger (on update) on it. When the trigger is executed I would like to know the name of the stored procecure which updated the table in question.
This won’t always be 100% reliable, and it sometimes will capture the outer procedure call even if that procedure called an inner one. But you can at least get some idea of what the user called that ended them up in the trigger.
Stolen from Vyas K: http://vyaskn.tripod.com/tracking_sql_statements_by_triggers.htm
You may also want to check out this question, which has an answer relating to using
sys.dm_exec_query_stats– you can track back to procedure name using the object id exposed bysys.dm_exec_sql_text, and you can limit to very recent invocations usingGETDATE()as a guide for “recent.” There is also a lengthy example of using Extended Events to do it.Create Trigger to log SQL that affected table?
Or these ones which use
CONTEXT_INFO(but this requires changing all of the stored procedures that update the table):Find query that fired a trigger
Is it possible for a trigger to find the name of the stored procedure that modified data?
Finally, you may check out these posts for some ideas:
http://www.thecodepage.com/post/TIP-A-Call-Stack-in-SQL-Server.aspx