I have a MySQL database with two tables in it: drivers and devices
The drivers table has a field called expiration date.
The devices table has a field called status.
My goal is to create a event that will :
- Get current Date
- Compare drivers (expiration date) with current date
- If the expiration date is passed then it needs to change the status of the device to ‘EXP’
Is something like this possible?
It is like a expiration check
2
Answers
This is the query your event will need to execute:
As about the creation of the event, you have multiple options, some of which are listed here:
Whatever the case, you may want to wrap your
UPDATE
into a stored procedure and you may also want to wrap a transaction around the call of this event, especially if there are more write operations.Okay, so considering the following
MySQL
Table Structure:You’d need to run through each driver, see if it has expired and update the device properly.
First, you need to enable
EVENTS
in your database:Next, you can just create an
event
that runs each day, checks all theactive
devices forexpired
drivers and updates appropriately: