Trigger for update before insert

4

My database has two tables, the notification and the service, as the image shows.

Inthenotificationtablethedefaultstatusvalueis"open."

I tried to do a trigger that updates the default status "open" to "on-call" after a new call is entered in the attendance table My trigger ended up changing the status of all the records in the notification table, and I want to change only the status of the notification that is referenced in the attendance table.

Below is my trigger code

DELIMITER //
CREATE TRIGGER atualizanotificacao BEFORE INSERT ON atendimento
FOR EACH ROW
BEGIN
    UPDATE notificacao SET status = "Em atendimento" WHERE idnotificacao = idnotificacao;

END
// DELIMITER ;
    
asked by anonymous 16.06.2017 / 22:03

1 answer

3

It is changing all records because idnotification = identification is the same as 1 = 1. on all lines this condition would return true.

DELIMITER //
CREATE TRIGGER atualizanotificacao BEFORE INSERT ON atendimento
FOR EACH ROW
BEGIN
    UPDATE notificacao SET status = "Em atendimento" WHERE idnotificacao = NEW.idnotificacao;

END
// DELIMITER ;

This NEW that I added means that I will get the idnotification value that will be entered in the attendance table, idnotification without NEW is the same notification table.

>     
16.06.2017 / 22:07