
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we modify an existing MySQL event?
With the help of ALTER EVENT statement, we can modify an existing MySQL event. We can change the various attributes of an event. ALTER EVENT has the following syntax −
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 are illustrating the example as below −
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 alter the schedule of the event from 1 minute to 2 minutes. And the query below 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 got the changed message after 2 minutes.
- Related Articles
- How can we RENAME an existing MySQL event?
- How can we delete an existing MySQL event permanently?
- How can we modify an existing module in Java 9?
- How can I modify an existing MySQL column’s data type?
- How can I move an existing MySQL event to another database?
- How can I modify an existing column's data type?
- How can we modify column/s of MySQL table?
- How can we start MySQL event scheduler?
- How can we delete an existing MySQL table by using PHP script?
- How can we get a list of columns in an existing MySQL table?
- How can we add columns with default values to an existing MySQL table?
- How can we create a table from an existing MySQL table in the database?
- How can we add multiple columns, with single command, to an existing MySQL table?
- How can we insert data into an existing MySQL table by using PHP script?
- How can we apply UNIQUE constraint to the field of an existing MySQL table?

Advertisements