Solved

How do I prevent a recursive Interbase trigger

Posted on 2010-09-23
2
1,230 Views
Last Modified: 2013-12-09
How do I update multiple rows in a table using a trigger without encounting a recursive trigger scenario? For instance, you change the price for an item in Group 1, the idea would be for the trigger to set the price for every other item in the table in Group 1 to the same price. However, this is an easy scenario to encounter a recursive trigger when running an update statement on the same table. Any ideas on how to accomplish this with a trigger or trigger/procedure?

Example:

Item     Price     Group
Item1   1.00      1
Item2   2.00      2
Item3   1.00      1

Edit price for Item 1 to 3.00 should also change Item3 to 3.00.
0
Comment
Question by:PilotAdmin
2 Comments
 
LVL 19

Accepted Solution

by:
NickUpson earned 500 total points
ID: 33752300
in an after update trigger

if exists (select 1 from mytable where group = new.group and price <> new.price)) then
  update mytable set price = new.price where group = new.group;

this is untested pseudo code, but you should get the idea






0
 

Author Closing Comment

by:PilotAdmin
ID: 33798466
After update suggestion worked.. had to manage it a bit different due to the example I provided being a little oversimplified (we have a lot more going on in the price table that I didn't go into), but it did get me going down the right track. Thanks!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now