Using Triggers and Events in MySQL

Published July 26, 2025 By Sai Sree Ram Gundepudi

AFTER INSERT Trigger

CREATE TRIGGER log_insert
AFTER INSERT ON employees
FOR EACH ROW
INSERT INTO audit_log(action) VALUES ('Inserted employee');

Scheduled EVENT

CREATE EVENT purge_logs
ON SCHEDULE EVERY 1 DAY
DO DELETE FROM audit_log WHERE log_date < NOW() - INTERVAL 7 DAY;

Was this solution helpful?

Your feedback helps improve our technical knowledge repository.

Share this article