I have the following trigger created in phpMyAdmin:
Table: tb_agenda
Time: AFTER
Event: INSERT
BEGIN
INSERT INTO tb_realizacao (dt_agenda,
titulo,
titulo_en,
descricao,
descricao_en,
dt_cadastro)
SELECT dt_agenda,
titulo,
titulo_en,
descricao,
descricao_en,
dt_cadastro
FROM tb_agenda
WHERE dt_agenda < NOW();
DELETE FROM tb_agenda
WHERE dt_agenda < NOW();
END
The trigger works 50%. The INSERT instruction works perfectly but the DELETE one doesn't execute. I tried to execute it in the SQL panel and it works fine.
NOW(). – Rick James Jun 23 '15 at 01:32SELECTstatement in an after insert trigger? And Also it maybe better to provide the full trigger body. – Masoud Jun 23 '15 at 01:52NOW()returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger,NOW()returns the time at which the function or triggering statement began to execute.) This differs from the behavior forSYSDATE(), which returns the exact time at which it executes. – Michael - sqlbot Jun 23 '15 at 11:31DELETEthe row whoseINSERTcaused the Trigger to fire; that won't work -- TheINSERTdoes not happen until the Trigger finishes. That is, theDELETEdid run, but found nothing to delete. – Rick James Jun 23 '15 at 16:58tb_agendathat everytime it's populated with new data, the trigger inserts intotb_realizacaothe data fromtb_agendawhichdt_agenda(date) is less thanNOW(), then exclude these old data fromtb_agenda. Summarizing, thetb_agendais the next events that will happen, andtb_realizacaois the events that already happened. – Jun 23 '15 at 17:37tb_realizacao, when adding a new data only one fromtb_agendais added into the other table, not to mention the DELETE doesn't work. I don't know what to do. – Jun 23 '15 at 22:32