sidewaysglance
sidewaysglance

Reputation: 177

MySQL trigger delete field after a period on update

I want to automatically delete recovery_url from table users 30 minutes after it's been updated. Is there any way of doing this?

Thanks

Upvotes: 0

Views: 60

Answers (1)

juergen d
juergen d

Reputation: 204874

One way I can think of is using an additional column indicating how long the recovery_url is valid. It can be a datetime column and in your queries you can select the recovery_url depending on that date. So you don't need any triggers or events.

select case when url_valid_until < now()
            then null
            else recovery_url 
       end as recovery_url 
from your_table

Upvotes: 1

Related Questions