Subject Re: [ib-support] Trigger to update a table
Author Ivan Prenosil
> 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

A) this should be enough:

IF (NEW.CODE<>OLD.CODE)
THEN Update_DT = 'Today';

B) because the CODE field is not defined as NOT NULL,
you would probably want to catch cases when CODE changes
form NULL to some not null value or vice versa.

C) instead of 'Today' literal you can use CURRENT_TIMESTAMP.


Ivan
http://www.volny.cz/iprenosil/interbase