Is there a parameter passage in a Rigger?

Asked

Viewed 609 times

5

I have two tables, one with the sessions and the other with the activities. Within the table activities I have two fields, available and saleable and within session I have vacancies.

I would like to get the session id so I can update to the sellable field, when I reset the vacancies that the activity field.sellable update to 0.

DELIMITER $$
CREATE TRIGGER atualizarStatus
AFTER UPDATE ON sessao
FOR EACH ROW
BEGIN
IF (sessao.vagas = 0) THEN
UPDATE atividade SET vendivel = 0 WHERE id = $id;
END IF;
END;
  • This is not the idea of triggers, you might want to run a precedent. The only "parameters" in a Rigger are the new lines new.* and ancient old.*

  • A doctor can do what I want?

1 answer

1


Your attempt was very close to achieving the goal. Try it this way:

DELIMITER $$
CREATE TRIGGER atualizarStatus
   AFTER UPDATE ON sessao 
     FOR EACH ROW
   BEGIN
   IF NEW.vagas = 0 THEN
      UPDATE atividade SET vendivel = 0 WHERE id = NEW.id;
   END IF;
END;

On Trigger, the reserved words NEW and OLD allow access to the columns of the records that were affected by the instruction that triggered Trigger. In this case you can use NEW to access the registry status after UPDATE.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.