Subject tricky trigger
Author martinknappe
hi
thx for your quick replies to my other post
here goes another problem i'm having, but first a quick brief on the
relevant fields in my db necessary for understanding my point:

my database contains - amongst others - the following table:

CREATE TABLE DICENTRIES (
ID BIGINT NOT NULL,
ASTERM S_CHAR_80,
ASVERWID BIGINT,
ASVERWTERM S_CHAR_80,
//more fields; not relevant here
);

plus the following foreign keys:

ALTER TABLE DICENTRIES ADD CONSTRAINT FK_DICENTRIES_2 FOREIGN KEY
(ASVERWID) REFERENCES DICENTRIES (ID) ON UPDATE CASCADE;


as you see, asverwid references id of another entry.
i also have a trigger that does the following: upon insert of a new
entry, it checks whether asverwid has been assigned any value and if
so it goes out and looks for the corresponding asterm (i.e. "where id
= new.asverwid") and inserts this value into new.asverwterm.

this all works; now comes the problem:

what i also need is a trigger that upon update does this: check
whether there are any entries where asverwid = new.id and if so,
update the corresponding field "asverwterm"

what i've written is the following trigger but it doesnt work :-(

CREATE trigger dicentries_bu0 for dicentries
active before update position 0
as
declare variable wanted_id bigint;
begin
for select id from dicentries where asverwid = new.id into :wanted_id do
begin
update dicentries
set
asverwterm = new.asterm
where
ID = :wanted_id;
end
end


does any of you see why it doesnt work?

thanx,

martin