Re: Triggers

From: F van Nimwegen <fred.van.nimwegen_at_gmail.com>
Date: Sun, 8 Aug 2010 03:30:29 -0700 (PDT)
Message-ID: <eb7e95d1-1b9c-4242-91b7-2522cedbcbf6_at_14g2000yqa.googlegroups.com>



On Aug 8, 12:57 am, The Magnet <a..._at_unsu.com> wrote:
> On Aug 7, 5:30 pm, The Magnet <a..._at_unsu.com> wrote:
>
> > Is there really any good way to track the changed columns in a trigger
> > on an update?
>
> > Say I have a table of 100 columns and I am doing some history
> > recording into another table for 50 of those columns.  Putting 50 IF
> > statements is lame.  Is there a better way to do it?
>
> > Maybe something similar to
> > DECODE(email,:NEW.email, :NEW.email, :OLD.email)
>
> I was thinking and I guess I should be more explicit:
>
> On an UPDATE trigger, which column values are :NEW and which
> are :OLD.   If I update column A and need the values for column B & C
> for something else, do I reference them as :NEW or :OLD (this is a
> BEFORE trigger).
>
> So, UPDATE tablex SET a = 'ABC';
> Then, UPDATE history SET a=:NEW.a, b=????,  c=????
>
> Now, columns B & C, are they :NEW or :OLD?  Do I need to test each
> column I need to get the actual value?

The actual value is the :new value.

With the on delete trigger you can only use :old

will you always write to history or only when one of the 50 columns are changed?
When you always write history their is no need to test when you only write history when one of the 50 columns are changed you had to test Received on Sun Aug 08 2010 - 05:30:29 CDT

Original text of this message