Jump to content

keeping track of "deleted" rows


dadamssg87

Recommended Posts

Right now, my users can delete pieces of content that they've created and the rows really do get deleted from the database. I'd like to change this by adding a "deleted" column in my database table. The column datatype needs to hold the date/time of deletion. So i'm thinking datetime, timestamp, or int(11). I'm just not sure which datatype is ideal. I was just going to set the datatype to int(11) to store the integer value of the timestamp of when the row was "deleted". Then i could just query non-deleted items by "select * from table where deleted != '0'". But i think i should be using datetime or timestamp. I don't really understand the difference between the two.

 

What do the mysql wizards suggest?

Link to comment
Share on other sites

I dunno about the wizards, but I would use a timestamp field with default value of NULL and no on update action.

Update it it with CURRENT_TIMESTAMP() when something is deleted, then select the info by NOT using * with the WHERE <timestamp_filed> IS NOT NULL.

 

Using a date time formated field lets you report against the filed (as I am assuming you want to do or else you would just be using a flag field) without having to convert values to get the ranges that you are looking for.

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.