What is MySQL event and how it is related to trigger?

MySQLMySQLi Database

A MySQL event is a task that rums based on a predefined schedule therefore sometimes it is referred to as a scheduled event. In other words, we can say that the MySQL event schedule is a process that runs in the background and constantly looks for the events to execute. It is referred to as a temporal trigger because they triggered by time and not like triggers that execute based on the table update. We can use events to run either once or at a recurring interval. They can be used to create backups, delete stale records, aggregate data for reports, and so on. Its syntax would be as follows −


CREATE EVENT event_name
   ON SCHEDULE schedule


  • event_name is the name of the event that we must have to specify after CREATE EVENT statement. It must be unique in a database.
  • The schedule is the time that we need to specify so that the event can occur at that particular time or schedule. The event can be a one-time event or recurring event.
  • Event_body is the set of SQL statements that we need to specify after the DO keyword. It can be wrapped in BEGIN…END block if there are multiple statements.
Published on 22-Feb-2018 12:20:18