473,471 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

No Cascade on Before Trigger firing other triggers

We are have a question about the no cascade option on before triggers.
The description stays that no other triggers will be fired by the
changes of a before trigger. One of our developers is seeing results
that would imply that other after triggers are being fired by the
results of a before trigger.

Is this possible? Is there some little documented behavior going on
here?

thanks

Jack Baker
Nov 12 '05 #1
2 6976
Thanks Serge

What you describe makes sense and is consistent with the behavior we are seeing.

jb

Serge Rielau <sr*****@ca.eye-be-em.com> wrote in message news:<c9**********@hanover.torolab.ibm.com>...
Jack,

Best illustrated with an example:

CREATE TABLE T(c1 INT, c2 INT);

INSERT INTO T VALUES (1, 1);

CREATE TRIGGER trg1 NO CASCADE BEFORE UPDATE OF c1 ON T
REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL
SET new.c2 = new.c1;

CREATE TRIGGER trg2 NO CASCADE BEFORE UPDATE OF c2 ON T
REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL
SET new.c1 = new.c2 + 1;

CREATE TRIGGER trg3 AFTER UPDATE OF c2 ON T
REFERENCING NEW AS n FOR EACH ROW MODE DB2SQL
INSERT INTO T VALUES (-new.c1, -new.c2);

UPDATE T SET c1 = 5;

SELECT * FROM T ORDER BY c1;
=> (5, 5), (-5, -5)

So what happend? The SET statement in trg1 effectively added c2 to the
list of updated values, however this knowledge did NOT CASCADE to trigger2.
That one only bothers with the original SET clause of the update,
otherwise the SET statement in trg2 could send the system into a forever
cascade.
The AFTER trigger on the other hand sees whatever effectively happend to
the row.
Note that cascading for after triggers isn't an issue since you can't
SET the values after the fact. You can "only" cause recursion with
embedded UPDATE statements.
So if you saw after triggers firing that would be as designed.

Cheers
Serge

Nov 12 '05 #2
*phew*You got me sweating there for a momment ;-)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and...
6
by: Antonios Christofides | last post by:
Hi, I've prepared a test case about this, which I include below. I have tables "a" and "b"; "b" has a foreign key to "a", on delete cascade. In addition, there is a "before delete on b" trigger,...
2
by: R.Welz | last post by:
Hello. I want to discuss a problem I have with my database design becourse I feel I cannot decide wheather I am on the right way of doing things. First of all, I am writing a literature and...
8
by: Frank van Vugt | last post by:
Hi, If during a transaction a number of deferred triggers are fired, what will be their execution order upon the commit? Will they be executed in order of firing or alfabetically or...
2
by: Net Virtual Mailing Lists | last post by:
Hello, If I have a rule like this: CREATE OR REPLACE RULE sometable_update AS ON UPDATE TO table2 DO UPDATE cache SET updated_dt=NULL WHERE tablename='sometable'; CREATE OR REPLACE RULE...
1
by: aj70000 | last post by:
hi, Here's the scenario 1) I am running a DTS job to fetch some rows from Oracle 2) The job populates the Table A as step 1 3) Then it fires a update statement which updates the rows in Table...
2
by: nekiv90 | last post by:
Greetings, I have to delete older policies and its related records in other tables. The deletion from the parent table will trigger the deletion of relevant records from about 30 something...
1
by: Nemisis | last post by:
Hi everyone, Wonder if anyone can shed some light on how i should setup cascade deletes of object data within my database. One option is to use SQL triggers, is this a good idea? Should the...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.