Dengan bantuan pernyataan ALTER EVENT, kami boleh mengubah suai acara MySQL sedia ada. Kita boleh mengubah pelbagai sifat acara tersebut. Sintaks ALTER EVENT adalah seperti berikut:
ALTER EVENT event_name ON SCHEDULE schedule ON COMPLETION [NOT] PRESERVE RENAME TO new_event_name ENABLE | DISABLE DO event_body
Untuk memahaminya, kami akan memberikan contoh seperti berikut-
Andaikan kita mempunyai acara seperti berikut-
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)
Pertanyaan di atas akan mengubah jadual acara dari 1 minit hingga 2 minit. Pertanyaan berikut akan menukar badan acara.
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)
Keputusan yang ditetapkan di atas menunjukkan bahawa kami menerima mesej yang ditukar selepas 2 minit.
Atas ialah kandungan terperinci Bagaimanakah kita mengubah suai acara MySQL sedia ada?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!