Comments inline...

----- Original Message -----
From: "Jochem van Dieten"

> > CREATE OR REPLACE TRIGGER hhp_calendar.trg_hhp_calendar_id
> > BEFORE INSERT  OR UPDATE
>
> We don't really want to change the primary key when we update, do we?

No, and the original version of that trigger used the updating portion to
explicitly disallow changing the primary key (Daniel chopped it off in his
version).

>
> > ON hhp_calendar.hhp_calendar
> > REFERENCING NEW AS NEW OLD AS OLD
> > FOR EACH ROW
> > DECLARE
> > iCounter hhp_calendar.id%TYPE;
> > cannot_change_counter EXCEPTION;
>
> IIRC most of this is optional.

true, but it was the example I was given when I was learning how to write
triggers - a bit verbose, but accurate. I should have stripped it down
before sending it. But, I didn't feel like taking the time.

> > BEGIN
>
> > IF INSERTING THEN
>
> If we don't define the trigger for updates, we don't need the IF
> later on either :)
>
>
> > Select uniqueNum_s.NEXTVAL INTO iCounter FROM Dual;
> > :new.id := iCounter;
>
> No need for a temp var, you can select into new:id directly.
>
> So I suppose we end up with:
>
> CREATE OR REPLACE TRIGGER hhp_calendar.trg_hhp_calendar_id
> BEFORE INSERT ON hhp_calendar.hhp_calendar FOR EACH ROW
> BEGIN
>    SELECT uniqueNum_s.nextval INTO :new.id FROM dual;
> END;
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to