Subject | Re: [ib-support] Trigger to update a table |
---|---|
Author | Lucas Franzen |
Post date | 2001-11-29T17:46Z |
Clément Doss schrieb:
Change it to:
CREATE TRIGGER UpdateDate FOR MYTABLE
BEFORE UPDATE AS
BEGIN
IF (NEW.CODE<>OLD.CODE) then NEW.Update_DT = 'Today'
END
In a trigger you have access to ALL the fields of the updated record.
You can refer to them by OLD and NEW.
Never do "update table" in an update trigger (at least not on the same
table since his might lead to recursion).
Luc.
>Yes.
> Hello,
>
> I have a table like
> CREATE TABLE "MYTABLE"
> (
> "CODE" INTEGER,
> "UPDATE_DT" DATE
> );
>
> I would like to update the field Update_DT when CODE is updated.
> I am trying to use the trigger below...
>
> CREATE TRIGGER UpdateDate FOR MYTABLE
> #1 BEFORE UPDATE AS
> BEGIN
> IF (NEW.CODE<>OLD.CODE) then begin
> UPDATE MYTABLE
> SET Update_DT = 'Today'
> #2 Where MyTable.Code = Old.Code;
> end
> END
>
> I am unable to update the Date.
> Any clues?
Change it to:
CREATE TRIGGER UpdateDate FOR MYTABLE
BEFORE UPDATE AS
BEGIN
IF (NEW.CODE<>OLD.CODE) then NEW.Update_DT = 'Today'
END
In a trigger you have access to ALL the fields of the updated record.
You can refer to them by OLD and NEW.
Never do "update table" in an update trigger (at least not on the same
table since his might lead to recursion).
Luc.