---

## slug: /pl-event

# EVENT

An event is a predefined SQL task that can be automatically executed at specific times or at specified intervals. Each event consists of a trigger condition (i.e., a schedule), an SQL statement, or a stored procedure. The event definition is stored in the database and is maintained along with the database, ensuring that the event will execute as scheduled even after a server restart.

Unlike triggers, which are triggered by data operations, events are triggered by time changes. This allows users to automatically execute SQL statements or stored procedures based on predefined time schedules. This feature significantly enhances the database's ability to handle automation, making it suitable for various scenarios such as regular data maintenance, statistical aggregation, and scheduled notifications.

:::info

seekdb events support the execution of `call` statements to invoke stored procedures, and time expressions and functions are supported when setting the start or end time.

:::

**Features**:

* Scheduling rules:

  * Specific time point: You can set the event to execute at a specific time point.
  * Periodic execution: Supports repeating execution at intervals of seconds, minutes, hours, days, or months.
  * Complex scheduling: By combining keywords such as `EVERY`, `STARTS`, and `ENDS`, complex scheduling logic can be implemented, such as executing only on weekdays or within specific date ranges.

* SQL support:

  * Any valid SQL statement, including data insertion, update, and deletion, can be executed.
  * Supports transaction processing to ensure atomicity and consistency of event execution.

* Dynamic control:

  * You can dynamically enable or disable the event scheduler at runtime without restarting the service.
  * Supports modification and deletion of existing events to adapt to changing business needs.

## Privilege requirements

To use events, you must have the `GRANT EVENT` privilege. For more information about seekdb privileges, see [Privilege types in seekdb]()].

## Start and stop events

Events are executed by a special event scheduler thread. You can start or stop the event scheduler as follows:

* Start the event scheduler:

    ```shell
    SET GLOBAL event_scheduler = ON;
    ```

* Stop the event scheduler:

    ```shell
    SET GLOBAL event_scheduler = OFF;
    ```

## Usage and considerations

* If `EVERY interval` is not set with `START TIME` or `END TIME`, the event will run indefinitely.
* For recurring events, if the execution time exceeds the scheduling interval, multiple events may execute simultaneously at the same time. Users must ensure that the execution time is less than the scheduling interval.
* The maximum execution time for a one-time event is 24 hours.
* It is not recommended to create one event from another.
* Once an event has started, its schedule cannot be modified.
* Once an event has started, its `event_name` should not be modified, as this may prevent it from ending correctly.
* If an event fails to execute 16 times consecutively, it will stop running.