开发者

Get caller of trigger in SQL Server

Can you advice me how I can retrieve caller ID or Name which executed a trigger?

For example I want to know which SP executes a trigger or maybe trigger called by updates from manage开发者_JS百科ment studio?

I know that @@PROCID returns ID of trigger and can't be used.

Also I know solution when in SP we write CONTEXT_INFO and read it from trigger. But in this case we should SET CONTEXT_INFO in all SPs that modifies some table.

Is there exists some simplest way like @@PROCID ?


If it's SQL Server 2005 or 2008, and a DDL trigger, you can use eventdata().

Here's a link to the msdn page.

Basically it returns an XML dataset that you can parse to get things like who called it (data(/EVENT_INSTANCE/LoginName)[1]), what the command was, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜