Behseini
Behseini

Reputation: 6320

How to write a MySQL event script

How can I create a MySQL event that can be run every 10 minutes and update the table based on TIMESTAMP column? I have a table like:

enter image description here

Now I need to have a My SQL event which can loop to the table and update all pending from 1 to 0 IF/WHERE Date is 10 minutes older than CURRENT_TIMESTAMP on event time.

CREATE EVENT test_event
ON SCHEDULE EVERY 10 MINUTE
STARTS CURRENT_TIMESTAMP
ENDS CURRENT_TIMESTAMP + INTERVAL 10 MINUTE
DO
UPDATE `pending` SET = 0 WHERE `Date` > CURRENT_TIMESTAMP

Upvotes: 1

Views: 102

Answers (1)

sid
sid

Reputation: 363

With help of a cronjob you can achieve this easily. Just create a script on backend which would run the script.

What is cronjob?

you can read more about the cronjobs works: https://www.geeksforgeeks.org/how-to-setup-cron-jobs-in-ubuntu/

Upvotes: 0

Related Questions