ALTER TRIGGER "tdb_pa_erisood" before delete order 1 on
DBA.pa_erisood
referencing old as old_name
for each row
begin
  update "pa_erisood_id" set "id" = if "pa_erisood_id"."id" > old_name."id" then old_name."id" else "pa_erisood_id"."id" endif where "pa_erisood_id"."aasta" = old_name.a_aasta;
  if old_name.v_aasta>2020 then
    call pr_kanne_add(old_name.v_akuu,old_name.v_aasta,get_skoop(5,old_name.yksusnr),5);
  end if;
end