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
– Don't Panic
You have not installed Phpmyadmin ??
– Sveen
CURRENT_TIMESTAMP()
in place ofCURRENT_TIMESTAMP
, the tableevento_pertence_grupo
has notN
records for the same event? then there should be agroup by
ai– Don't Panic
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 ?
– Guilherme Bornia
@Guilhermebornia Yes,
group by grupo_id_ref
, unless an event has 2 groups, give instead of beingWHERE grupo_id =
has to beWHERE grupo_id IN
– Don't Panic
Thanks, it worked!
– Guilherme Bornia