Home > Mobile >  trigger in mysql update
trigger in mysql update

Time:10-17

I have these tables and I want to write a trigger that, when I carry out an insert statement in "tache", given that datedif(datestart,dateend) > 30, I want to update table "employe" and set salaire = salaire*0.5

  • Table 1: employe (mle, salaire)
  • Table 2: tache (mle, datestart, dateend)

Here's my non-working attempt:

drop trigger if exists set_5_slr;

delimiter $$

create trigger set_5_slr 
before insert on réalise 
FOR EACH ROW
BEGIN
    if datediff(new.dateDébut,new.datefin)>30 
    then UPDATE TABLE employé set salaire=salaire (salaire*0.5)  where mle=new.mle;
    end if;
end ;

delimiter ;

Can you help me with this issue?

CodePudding user response:

this is solution

delimiter $$
create TRIGGER réalise_AFTER_INSERT AFTER INSERT ON réalise FOR EACH ROW
BEGIN
    if abs(datediff(new.dateDébut,new.datefin))>30 then 
            UPDATE employé set salaire=salaire*1.5 where mle=new.mle;
    end if;
END $$
delimiter ;
  • Related