Solved

How do I prevent a recursive Interbase trigger

Posted on 2010-09-23
2
1,224 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
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…

759 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

20 Experts available now in Live!

Get 1:1 Help Now