How to do an operation on a Trigger? MYSQL

0
CREATE TRIGGER aumentarsalario 
AFTER INSERT 
ON empregados
FOR EACH ROW
BEGIN
  UPDATE EMPREGADOS SET SALARIO = NEW.SALARIO * (NEW.SALARIO*(10/100)) WHERE NEW.SALARIO < 900;
END IF
END

How do I put another 10% on a product? at which point I'm wrong.

    
asked by anonymous 17.05.2018 / 21:32

3 answers

0

You do not need to UPDATE to change the record itself. This trigger will be executed every time a new record is entered, the variable NEW will contain the data of this new record, so to do what you need just do SET NEW.coluna = valor .

CREATE TRIGGER aumentarsalario 
AFTER INSERT 
ON empregados
FOR EACH ROW
BEGIN
  SET NEW.SALARIO = NEW.SALARIO * 1.1 WHERE NEW.SALARIO < 900;
END IF;
END;
    
18.05.2018 / 13:54
0

Try this!

CREATE TRIGGER aumentarsalario 
  AFTER INSERT 
  ON empregados FOR EACH ROW
BEGIN
  UPDATE EMPREGADOS SET SALARIO = 1.1 * SALARIO WHERE SALARIO < 900;
END;
    
17.05.2018 / 21:42
0

I believe that this solves your problem:

create trigger AUMENTARSALARIO
after insert on EMPREGADOS
for each row
begin
  update EMPREGADOS set SALARIO = SALARIO * 1.1 where SALARIO < 900;
end;

You had left a END IF there that was not necessary; In addition, it made the salary receive ele mesmo * 10% , when it should add up.

    
18.05.2018 / 12:40