set term ^ ; ALTER TRIGGER AFTINS_FIRMA ACTIVE AFTER INSERT POSITION 0 AS declare variable arbgkey integer; declare variable arbzkey integer; begin insert into benutzerfirma (bn_key, fi_key, aktiv) select bn_key, new.fi_key, 'N' from benutzer; if (NEW.RBG_KEY <= 0 or NEW.RBG_KEY is null ) then delete from rabattzuordnung where fi_key = NEW.FI_KEY; else begin arbzkey = null; select rbz_key, rbg_key from rabattzuordnung where fi_key = NEW.FI_KEY into :arbzkey, :arbgkey; if (arbzkey is null) then insert into rabattzuordnung(fi_key, rbg_key) values (NEW.FI_KEY, NEW.RBG_KEY); else if (arbgkey <> NEW.RBG_KEY) then update rabattzuordnung set rbg_key=NEW.RBG_KEY where rbz_key = :arbzkey; end end ^ /* Trigger: AFTUPD_FIRMA */ CREATE OR ALTER TRIGGER AFTUPD_FIRMA FOR FIRMA ACTIVE AFTER UPDATE POSITION 0 AS declare variable arbgkey integer; declare variable arbzkey integer; begin if (NEW.RBG_KEY <= 0 or NEW.RBG_KEY is null ) then delete from rabattzuordnung where fi_key = NEW.FI_KEY; else begin arbzkey = null; select rbz_key, rbg_key from rabattzuordnung where fi_key = NEW.FI_KEY into :arbzkey, :arbgkey; if (arbzkey is null) then insert into rabattzuordnung(fi_key, rbg_key) values (NEW.FI_KEY, NEW.RBG_KEY); else if (arbgkey <> NEW.RBG_KEY) then update rabattzuordnung set rbg_key=NEW.RBG_KEY where rbz_key = :arbzkey; end end ^ commit^