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

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.