Home  >  Article  >  Database  >  What is a MySQL event and how does it relate to triggers?

What is a MySQL event and how does it relate to triggers?

王林
王林forward
2023-09-14 14:41:021482browse

什么是 MySQL 事件以及它与触发器有何关系?

#MySQL event is a task that runs based on a predefined schedule, so it is sometimes called a scheduled event. In other words, we can say that the MySQL event dispatcher is a process that runs in the background and is constantly looking for events to execute. It is called temporary triggers because they are triggered by time and not like triggers that execute based on table updates. We can use events to run once or periodically. They can be used to create backups, delete stale records, aggregate reporting data, and more. Its syntax is as follows -

Syntax

CREATE EVENT event_name
   ON SCHEDULE schedule
DO
   Event_body

Here,

  • event_name is the event name that we must specify after the CREATE EVENT statement. It must be unique in the database.
  • Schedule is the time we need to specify so that the event can happen at that specific time or schedule. The event can be a one-time event or a recurring event.
  • Event_body is a set of SQL statements that we need to specify after the DO keyword. If you have more than one statement, you can wrap it in a BEGIN…END block.

The above is the detailed content of What is a MySQL event and how does it relate to triggers?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete