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 108345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:53:50+00:00 2026-05-11T01:53:50+00:00

Suppose you have the tables Presentations and Events . When a presentation is saved

  • 0

Suppose you have the tables Presentations and Events. When a presentation is saved and contains basic event information, such as location and date, an event will be created automatically using a trigger. (I’m afraid it’s impossible for technical reasons to simply keep the data at one place and use a view.) In addition, when changing this information later on in the presentation, the trigger will copy the updates over to the event as well, like so:

CREATE TRIGGER update_presentations ON Presentations AFTER UPDATE AS BEGIN     UPDATE Events     SET Events.Date = Presentations.Date,         Events.Location = Presentations.Location     FROM Presentations INNER JOIN Events ON Presentations.EventID = Events.ID     WHERE Presentations.ID IN (SELECT ID FROM inserted) END 

Now, the customer wants it so that, if a user ever changes the information in the event, it should go back to the presentation as well. For obvious reasons, I can’t do the reverse:

CREATE TRIGGER update_events ON Events AFTER UPDATE AS BEGIN     UPDATE Presentations     SET Presentations.Date = Events.Date,         Presentations.Location = Events.Location     FROM Events INNER JOIN Presentations ON Events.PresentationID = Presentations.ID     WHERE Events.ID IN (SELECT ID FROM inserted) END 

After all, this would cause each trigger to fire after each other. What I could do is add a column last_edit_by to both tables, containing a user ID. If filled by the trigger with a special invalid ID (say, by making all user IDs of actual persons positive, but user IDs of scripts negative), I could use that as an exit condition:

    AND last_edit_by >= 0 

This might work, but what I’d like to do is indicate to the SQL server that, within a transaction, a trigger should only fire once. Is there a way to check this? Or perhaps to check that a table has already been affected by a trigger?


Answer thanks to Steve Robbins:

Just wrap the potentially nested UPDATE statements in an IF condition checking for trigger_nestlevel(). For example:

CREATE TRIGGER update_presentations ON Presentations AFTER UPDATE AS BEGIN     IF trigger_nestlevel() < 2         UPDATE Events         SET Events.Date = Presentations.Date,             Events.Location = Presentations.Location         FROM Presentations INNER JOIN Events ON Presentations.EventID = Events.ID         WHERE Presentations.ID IN (SELECT ID FROM inserted) END 

Note that trigger_nestlevel() appears to be 1-based, not 0-based. If you want each of the two triggers to execute once, but not more often, just check for trigger_nestlevel() < 3 in both triggers.

  • 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. 2026-05-11T01:53:50+00:00Added an answer on May 11, 2026 at 1:53 am

    I’m not sure about doing it per transaction, but do you need nested triggers switched on for other parts? If you switch them off on the server then a trigger won’t fire from another trigger updating a table.

    EDIT (answer from the comments): You will need to alter trigger A to use TRIGGER_NESTLEVEL

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

Sidebar

Ask A Question

Stats

  • Questions 268k
  • Answers 268k
  • 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 I think that you should rather leave it as is… May 13, 2026 at 1:04 pm
  • Editorial Team
    Editorial Team added an answer _imageView.hasHorizontalScroller = YES; - in this line you access property… May 13, 2026 at 1:04 pm
  • Editorial Team
    Editorial Team added an answer This should do it: $arr1 = array ( 0 =>… May 13, 2026 at 1:04 pm

Related Questions

Let's assume, we create a stored procedure that is supposed to retrieve customer details
Suppose you have these tables: RestaurantChains , Restaurants , MenuItems - with the obvious
My company performed a data migration recently (in a SQL Server 2005 database) and
Suppose you were setting up a database to store crash test data of various

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.