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

  • Home
  • SEARCH
  • 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 308447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:39:04+00:00 2026-05-12T07:39:04+00:00

Below is the code snippet with comments which describes the problem statement. We have

  • 0

Below is the code snippet with comments which describes the problem statement. We have an update trigger which internally calls another update trigger on the same table inspite of Recursive Trigger Enabled Property Set to false.

Would like to understand the reason for this as this is causing a havoc in my applications.

/* Drop statements for the table and triggers*/  

IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].   [t_upd_TestTrigger_002]'))
    DROP TRIGGER [dbo].[t_upd_TestTrigger_002]
IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[t_upd_TestTrigger_002]'))
    DROP TRIGGER [dbo].[t_upd_TestTrigger_001]
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TestTrigger]') AND type in (N'U'))
    DROP TABLE [dbo].[TestTrigger]


CREATE TABLE [dbo].[TestTrigger] /*Creating a test table*/
(
    [InternalKey] INT  NOT NULL,
    [UserModified] varchar(50) DEFAULT SUSER_SNAME()
) 


/* Please run the snippet below as seperate batch, else you will get 
   an error that 'CREATE TRIGGER' must be the first statement in a 
   query batch.

   CREATING A UPDATE TRIGGER FOR THE TEST TABLE
*/

CREATE TRIGGER [t_upd_TestTrigger_001] ON [dbo].[TestTrigger]
FOR UPDATE
AS
BEGIN
    --This trigger has some business logic which gets executed 
    print 'In Trigger 001 '
END

/* Please run the snippet below as separate batch, else you will 
   get an error that 'CREATE TRIGGER' must be the first statement 
   in a query batch.

   CREATING Another UPDATE TRIGGER FOR THE TEST TABLE 

   This trigger updates the audit fields in the table and it has to be 
   a separate trigger, We cannot combine this with other update triggers - 
   So table TestTrigger will have two FOR UPDATE triggers
*/


CREATE TRIGGER [t_upd_TestTrigger_002] ON [dbo].[TestTrigger]
FOR UPDATE
AS
    print 'bad guy starts'
UPDATE SRC
    SET UserModified = SUSER_SNAME()
    FROM inserted AS INS
    INNER JOIN dbo.[TestTrigger] AS SRC
        ON INS.InternalKey = SRC.InternalKey
        print 'bad guy ends'

/* INSERTING TEST VALUE IN THE TEST TRIGGER TABLE*/

INSERT INTO dbo.[TestTrigger](InternalKey,UserModified)
SELECT 1 ,'Tester1'  UNION ALL
SELECT 2,'Tester2' UNION ALL 
SELECT 3 ,'Tester3'

/* TestTrigger table has 3 records, we will update the InternalKey 
   of first record from 1 to 4.  We would expect following actions
   1) [t_upd_TestTrigger_001] to be executed once
   2) [t_upd_TestTrigger_002] to be executed once
   3) A message that (1 row(s) affected) only once.

   On Execution, i find that [t_upd_TestTrigger_002] internally triggers 
   [t_upd_TestTrigger_001].

   Please note Database level property Recursive Triggers enabled is 
   set to false.
*/

/*UPDATE THE TABLE  SEE THE MESSAGE IN RESULT WINDOW*/
UPDATE dbo.[TestTrigger]
SET InternalKey = 4
WHERE InternalKey = 1
  • 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-05-12T07:39:05+00:00Added an answer on May 12, 2026 at 7:39 am

    “Recursive Triggers enabled” does not affect transitive triggers.

    Which means that if trigger A updates a table in a manner that activates trigger B, and trigger B updates the same table, so that trigger A is run again, SQL Server has no way of detecting and inhibiting this endless loop. Especially since trigger B can update other tables, and a trigger on them could update the original table again – this could become as complex as you like.

    Eventually, the trigger nesting level limit will be reached, and the loop stops.

    I suspect that both of your triggers update the source table in some way. SQL Server can only detect recursive triggers if a trigger is activating itself. I suppose that’s not the case for you. Restructuring the triggers is the only clean way out.

    As a (hackery) idea: You could append a field to the table (data-type and value is irrelevant) that is updated by no operation but by triggers. Then change your second-order triggers to update that field. Add an IF UPDATE() check for that field to your first-order trigger. Prevent the now redundant update if the field has been set. If that makes sense. 😉

    MSDN: Using Nested Triggers, see sections “Direct recursion” and “Indirect recursion”.

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

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 217k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer var results = from a in myEntities.thing1 where MyList.Contains(a) select… May 12, 2026 at 11:22 pm
  • Editorial Team
    Editorial Team added an answer I'd say the image loading code in Gimp and ImageMagick… May 12, 2026 at 11:22 pm
  • Editorial Team
    Editorial Team added an answer Heinzi, If I'm understanding your question correctly, it seems like… May 12, 2026 at 11:22 pm

Related Questions

I have a Windows Service developed in C# and .NET 3.5 to perform various
I have a simple-ish cell renderer which is composed of a few JLabel s
SOLVED see Edit 2 Hello, I've been writing a Perl program to handle automatic
Working with Linq2Sql as a driver for a Wcf Service. Lets go bottom up....

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.