Dan
Dan

Reputation: 517

delete or change status of post or comment php,sql

I'm creating a social network,

Question: In a post, anytime an user wants to delete this post or a comment. Do I need to delete it from the database or just change its status in order it doesnt appear anymore and give the user the feeling its already deleted?

Example:

<button>Delete this comment</button>

SQL

    DELETE FROM table_posts WHERE...

OR

    UPDATE table_posts SET status="deleted" WHERE...

Which one is more suitable?

Upvotes: 0

Views: 399

Answers (1)

Denis Jr
Denis Jr

Reputation: 376

It depends...

There are two cases:

  • If you delete the record:

    • It will be removed from the database and you will not be able to retrieve it.
    • You will have a database that takes up less space.
    • Probably the search on the records will be faster, because there will be less records to search.
  • If you update and set the status to "deleted":

    • You will have this record in your database and may (or may not) display it to the user.
    • Usually this case is useful when you want to have a log with all user messages.
    • This will require more disk space.
    • Probably the search of the records will not be as fast as if they had been deleted, as there are more records to search.

What is the best? This will depend on your business rule.

Upvotes: 2

Related Questions