Subject Trigger and Update Cascade
Author Valdir Stiebe Junior
Hi, i have two tables called PESSOA and PESSOA_CTM. And a View called
V_PESSOA that is a inner join between these two tables. When inserting,
updating or deleting data at the view, the view triggers mantain the
consistency. And the ID_PESSOA_CTM is the same ID_PESSOA, is a PK FK update
cascade field.
Now i need an after update trigger on table pessoa that update the table
pessoa_ctm in some cases.
My question is:
1. In the update line, should i use where ID_PESSOA_CTM = NEW.ID_PESSOA or
should i use ... = OLD.ID_PESSOA?
2. The trigger execute before or after the update cascade?

Here is the code of my trigger:

create trigger PESSOA_AU for PESSOA
active AFTER UPDATE position 0
as
begin
if ((OLD.CLIENTE = 1) and (NEW.CLIENTE = 0)) then
update PESSOA_CTM set LIMITE_CREDITO = null where ID_PESSOA_CTM =
NEW.ID_PESSOA;
if ((OLD.FUNCIONARIO = 1) and (NEW.FUNCIONARIO = 0)) then
update PESSOA_CTM set LIMITE_COMPRA = null where ID_PESSOA_CTM =
NEW.ID_PESSOA;
end