esus
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
taa_lotacao
Parameters
Name
Type
Mode
Definition
begin if(tg_op = 'INSERT') then update tb_ator_papel set qt_referencia = (qt_referencia+1) where co_seq_ator_papel = new.co_prof; update tb_ator_papel set qt_referencia = (qt_referencia+1) where co_seq_ator_papel = new.co_unidade_saude; if(new.co_equipe is not null) then update tb_equipe set qt_referencia = (qt_referencia+1) where co_seq_equipe = new.co_equipe; end if; elsif(tg_op = 'UPDATE') then if (old.co_prof is null) and (new.co_prof is not null) then update tb_ator_papel set qt_referencia = (qt_referencia + 1) where co_seq_ator_papel = new.co_prof; elsif (old.co_prof is not null) and (new.co_prof is null) then update tb_ator_papel set qt_referencia = (qt_referencia - 1) where co_seq_ator_papel = new.co_prof; elsif (old.co_prof != new.co_prof) then update tb_ator_papel set qt_referencia = (qt_referencia + 1) where co_seq_ator_papel = new.co_prof; update tb_ator_papel set qt_referencia = (qt_referencia - 1) where co_seq_ator_papel = old.co_prof; end if; if (old.co_unidade_saude is null) and (new.co_unidade_saude is not null) then update tb_ator_papel set qt_referencia = (qt_referencia + 1) where co_seq_ator_papel = new.co_unidade_saude; elsif (old.co_unidade_saude is not null) and (new.co_unidade_saude is null) then update tb_ator_papel set qt_referencia = (qt_referencia - 1) where co_seq_ator_papel = new.co_unidade_saude; elsif (old.co_unidade_saude != new.co_unidade_saude) then update tb_ator_papel set qt_referencia = (qt_referencia + 1) where co_seq_ator_papel = new.co_unidade_saude; update tb_ator_papel set qt_referencia = (qt_referencia - 1) where co_seq_ator_papel = old.co_unidade_saude; end if; if (new.co_equipe is null) then update tb_equipe set qt_referencia = (qt_referencia - 1) where co_seq_equipe = old.co_equipe; elsif (old.co_equipe != new.co_equipe) then update tb_equipe set qt_referencia = (qt_referencia + 1) where co_seq_equipe = new.co_equipe; update tb_equipe set qt_referencia = (qt_referencia - 1) where co_seq_equipe = old.co_equipe; end if; elsif (tg_op = 'DELETE') then update tb_ator_papel set qt_referencia = (qt_referencia - 1) where co_seq_ator_papel = old.co_prof; update tb_ator_papel set qt_referencia = (qt_referencia - 1) where co_seq_ator_papel = old.co_unidade_saude; update tb_equipe set qt_referencia = (qt_referencia - 1) where co_seq_equipe = old.co_equipe; end if; return NULL; end;