Reputation: 3153
Suppose I include the built in MySQL timestamp into my fields on my database table.
Everytime I update the records it will update the timestamp.
I would like to delete records than are older than an hour. Any ideas for how best to do this?
I could have a loop checking the timestamp for all records or perhaps a trigger in the database?
Upvotes: 0
Views: 1158
Reputation: 76666
You can use a cronjob to schedule a query to be executed in a fixed time interval:
DELETE FROM table_name WHERE time_created < (UNIX_TIMESTAMP() - 3600);
Every time it's run, it will delete all records older than 1 hour (which is presumably what you want).
Upvotes: 5