Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> How do you get Triggers and Constraints to "get along"?

How do you get Triggers and Constraints to "get along"?

From: Brent Fegley <bdfegley_at_ptdprolog.net>
Date: 1997/01/13
Message-ID: <32DA3DF0.74CD@ptdprolog.net>#1/1

Hi! I am having a dilemma with the firing order of triggers and constraints in an Oracle 7.x database, and was hoping someone could help. Here's the problem:

Actions performed in a BEFORE INSERT trigger execute without error, but the insert itself fails due to violation of an integrity constraint. One of the actions performed in the trigger is the update of a SEQUENCE number using the pseudo-column "nextval". So the sequence number increases in value, but the insert itself fails, and I'm left with non-consecutive sequence numbers.

Though updating a sequence within a trigger is a somewhat trivial example, the problem it reveals has much broader implications:

  1. Why would I want to do anything with or within a trigger If I knew that the operation as a whole might not succeed because of an integrity constraint violation -- especially when some of the actions that comprise the "operation" cannot be rolled back?
  2. Assuming I want or need to use a trigger, how can I ensure that the actions it performs can be reversed if an integrity constraint fails? (I am assuming that, by design, Oracle executes triggers before checking integrity constraints.)

Any help or guidance would be greatly appreciated. TIA.

Received on Mon Jan 13 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US