Subject | Re: Trigger Position |
---|---|
Author | Adam |
Post date | 2006-07-04T23:31:30Z |
Chris,
I am not sure your examples are really helping you.
There are 6 different trigger types
1. BEFORE INSERT
2. AFTER INSERT
3. BEFORE UPDATE
4. AFTER UPDATE
5. BEFORE DELETE
6. AFTER DELETE
1 & 2 are only fired as a result of an insert.
3 & 4 are only fired as a result of an update.
5 & 6 are only fired as a result of an update.
The 'BEFORE' triggers fire before the operation (insert/update/delete)
is run. They allow you to modify the values (in the case of an insert
or update). You can not insert a child record inside a BEFORE INSERT
trigger because the master record does not yet exist.
The 'AFTER' triggers fire after the operation (insert/update/delete)
has been run. You can not modify the values in an after trigger. You
are able to insert child records in an AFTER INSERT trigger because
the master records do now exist.
So it goes
BEFORE INSERT TRIGGERS -> Insert into table -> AFTER INSERT TRIGGERS
etc
An unhandled exception in either a before or after trigger undoes that
entire operation including all work done inside both triggers.
The only time the position is even CONSIDERED is if you have multiple
triggers of the same type on the same table. If your table has
multiple BEFORE INSERT triggers, then the one with the lowest position
is run first, followed by the one with the second lowest position, etc
until all the BEFORE insert triggers have run.
Adam
I am not sure your examples are really helping you.
There are 6 different trigger types
1. BEFORE INSERT
2. AFTER INSERT
3. BEFORE UPDATE
4. AFTER UPDATE
5. BEFORE DELETE
6. AFTER DELETE
1 & 2 are only fired as a result of an insert.
3 & 4 are only fired as a result of an update.
5 & 6 are only fired as a result of an update.
The 'BEFORE' triggers fire before the operation (insert/update/delete)
is run. They allow you to modify the values (in the case of an insert
or update). You can not insert a child record inside a BEFORE INSERT
trigger because the master record does not yet exist.
The 'AFTER' triggers fire after the operation (insert/update/delete)
has been run. You can not modify the values in an after trigger. You
are able to insert child records in an AFTER INSERT trigger because
the master records do now exist.
So it goes
BEFORE INSERT TRIGGERS -> Insert into table -> AFTER INSERT TRIGGERS
etc
An unhandled exception in either a before or after trigger undoes that
entire operation including all work done inside both triggers.
The only time the position is even CONSIDERED is if you have multiple
triggers of the same type on the same table. If your table has
multiple BEFORE INSERT triggers, then the one with the lowest position
is run first, followed by the one with the second lowest position, etc
until all the BEFORE insert triggers have run.
Adam