Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9177737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:23:38+00:00 2026-06-17T17:23:38+00:00

Possible Duplicate: Is it possible for a trigger to find the name of the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:23:39+00:00Added an answer on June 17, 2026 at 5:23 pm

    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.

    ALTER TRIGGER dbo.whatever
    ON dbo.something
    FOR UPDATE
    AS
    BEGIN
        ... other trigger logic
    
        DECLARE @ExecStr varchar(50), @Qry nvarchar(255)
    
        CREATE TABLE #inputbuffer 
        (
          EventType nvarchar(30), 
          Parameters int, 
          EventInfo nvarchar(255)
        )
    
        SET @ExecStr = 'DBCC INPUTBUFFER(' + STR(@@SPID) + ')'
    
        INSERT INTO #inputbuffer 
        EXEC (@ExecStr)
    
        SET @Qry = (SELECT EventInfo FROM #inputbuffer)
    
        SELECT @Qry AS 'Query that fired the trigger', 
         SYSTEM_USER as LoginName, 
         USER AS UserName, 
         CURRENT_TIMESTAMP AS CurrentTime
    
       -- of course you can store this somewhere instead of select
    END
    

    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 by sys.dm_exec_sql_text, and you can limit to very recent invocations using GETDATE() 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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Throw an error in a MySQL trigger I have a table definition
Possible Duplicate: trigger an event when contenteditable is changed I have a table on
Possible Duplicate: Trigger based on sysdate 1.I have a table on which i have
Possible Duplicate: jquery trigger - ‘change’ function I have a radio button set called
Possible Duplicate: mysql getting last_insert_id() in a trigger I have MySQL TRIGGER firing AFTER
Possible Duplicate: Trigger Heap Dump of a 1.5 JVM running on Windows I have
Possible Duplicate: Reset JavaScript Counter? I'm trying to create a function that will trigger
Possible Duplicate: Oracle table change monitor This is the question that is asked to
Possible Duplicate: How to execute a JavaScript function when I have its name as
Possible Duplicate: How do you trigger javascript functions from flash? Possible Duplicate: How do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.