Home >Database >Mysql Tutorial >How do we modify existing MySQL events?

How do we modify existing MySQL events?

WBOY
WBOYforward
2023-08-27 19:49:061385browse

我们如何修改现有的 MySQL 事件?

With the ALTER EVENT statement, we can modify existing MySQL events. We can change various properties of the event. The syntax of ALTER EVENT is as follows:

   ALTER EVENT event_name
    ON SCHEDULE schedule
ON COMPLETION [NOT] PRESERVE
  RENAME TO new_event_name
    ENABLE | DISABLE
           DO
       event_body

To understand it, we will give an example as follows-

Example

Suppose we have an event as follows-

mysql> Create event hello ON SCHEDULE EVERY 1 Minute DO INSERT INTO event_messages(message, generated_at) Values ('Alter event testing', NOW());
Query OK, 0 rows affected (0.00 sec)

mysql> select * from event_messages;
+----+---------------------+---------------------+
| ID | MESSAGE             | Generated_at        |
+----+---------------------+---------------------+
|  1 | Without Preserve    | 2017-11-22 20:32:13 |
|  2 | With Preserve       | 2017-11-22 20:35:12 |
|  3 | Alter event testing | 2017-11-22 21:08:37 |
+----+---------------------+---------------------+
3 rows in set (0.00 sec)

mysql> ALTER EVENT hello ON SCHEDULE EVERY 2 MINUTE;
Query OK, 0 rows affected (0.00 sec)

The above query will change the event's schedule from 1 minute to 2 minutes. The following query will change the body of the event.

mysql> ALTER EVENT hello DO INSERT INTO event_messages(message,generated_at) VALUES('ALTERED',NOW());
Query OK, 0 rows affected (0.00 sec)

mysql> select * from event_messages;
+----+---------------------+---------------------+
| ID | MESSAGE             | Generated_at        |
+----+---------------------+---------------------+
|  1 | Without Preserve    | 2017-11-22 20:32:13 |
|  2 | With Preserve       | 2017-11-22 20:35:12 |
|  3 | Alter event testing | 2017-11-22 21:08:37 |
|  4 | Alter event testing | 2017-11-22 21:09:15 |
|  5 | ALTERED             | 2017-11-22 21:11:15 |
+----+---------------------+---------------------+
5 rows in set (0.00 sec)

The above result set shows that we received the changed message 2 minutes later.

The above is the detailed content of How do we modify existing MySQL events?. 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