How to create triggers in BD using XAMPP?

Asked

Viewed 55 times

0

A group has N events and each event has M spending.

1) The following Trigger should update the last modification made in the group when an INSERT is made in the event table. Why it does not work?

CREATE TRIGGER trg_eventos AFTER INSERT ON eventos
FOR EACH ROW
BEGIN
    UPDATE grupos SET ultima_att = CURRENT_TIMESTAMP WHERE grupo_id = (
        SELECT grupo_id_ref FROM evento_pertence_grupo WHERE evento_id_ref = NEW.evento_id
    );
END

2) Can you create a Trigger for an INSERT, UPDATE and DELETE at once? For example:

CREATE TRIGGER faz_tudo AFTER INSERT, UPDATE, DELETE ON tabela
    1. No way, create a Rigger for each event.
  • You have not installed Phpmyadmin ??

    1. Seria CURRENT_TIMESTAMP() in place of CURRENT_TIMESTAMP , the table evento_pertence_grupo has not N records for the same event? then there should be a group by ai
  • I do have Phpmyadmin installed. CURRENT_TIMESTAMP is working because I tested it by removing the WHERE clause from the UPDATE, but with it there is no update in the records. In fact, there are N events for the same group. So you say to put a GROUP BY group_id_ref ?

  • @Guilhermebornia Yes, group by grupo_id_ref, unless an event has 2 groups, give instead of being WHERE grupo_id = has to be WHERE grupo_id IN

  • Thanks, it worked!

Show 1 more comment
No answers

Browser other questions tagged

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