Hi, Sami. I've been doing quite a bit recently with AFTER triggers, so hopefully I can shed some light.


Here's my question about ADDING a new record:
Can I issue an UPDATE statement on the same brand new record within the
Trigger using the AFTER INSERT syntax?
Yes, you can. You create an AFTER INSERT trigger that runs a stored procedure that can then:

UPDATE tablename SET whatever WHERE COUNT = INSERT

What I have done, though, is first retrive an index value WHERE CURRENT OF SYS_NEW then use that index value as the key for the subsequent update. This is probably more reliable than the COUNT=INSERT method.


When UPDATING an existing record:
Can I issue an UPDATE statement on the SAME record that is currently being
UPDATED?
Yes. In an AFTER UPDATE trigger, capture the key value WHERE CURRENT OF SYS_NEW into a variable. Then do a simple update where your key field matches the variable.

Your problem is going to be that if you have the AFTER INSERT and AFTER UPDATE both in existence on the table, and the AFTER INSERT performs an UPDATE to the table, it will probably fire the AFTER UPDATE trigger. (I have not verified this, but it would seem to be the case.) If this holds true, you might wish to do the real work only in the AFTER UPDATE and have your AFTER INSERT just set a column equal to itself WHERE CURRENT OF SYS_NEW in order to fire the AFTER UPDATE.


Emmitt Dove
Manager, DairyPak Business Systems
Blue Ridge Paper Products, Inc.
40 Lindeman Drive
Trumbull, CT 06611
(203) 673-2231
[EMAIL PROTECTED]
[EMAIL PROTECTED]



Reply via email to