Jump to content

How to Create A Token Table that Removes Rows After Specific Time?


TecTao

Recommended Posts

 

I am analyzing the tables of a DB created by another developer. One aspect I would like to use is a table that after a certain period of time table rows automatically delete.  This is their token table.  Among different things inserted is a time stamp that apparently sets a clock timer to remove the row after a period of time.  The information is automatically removed like a time driven cookie.

 

1) What would a table like this be called so I can research creating one?

 

2) What is it about this type of table that makes it unique to remove rows?

 

Thank you in advance.

Mike

MySQL doesn't have a scheduler (unlike MS SQL) so you can't do this using the database. Your best option is to have a cron job run which checks the database table for records that have expired and deletes them.

 

DELETE FROM <table name> WHERE `timestamp_column_name` < DATE_SUB(NOW(), INTERVAL 30 MINUTES)

 

This statement will delete all entries that are older than 30 minutes. You might want to test it though, as i did it "off the cuff".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.