Skip to content
Advertisement

Seperate tables with same attributes in SQL

When using SQL database, when I have tables with same attributes.

For example if I have

  • [posts] with attributes (id, image, description, number of likes and dislikes)
  • [Comments] with attributes (id, image, description, number of likes and dislikes)
    and
  • [Replies] with attributes (id, image, description, number of likes and dislikes)

and I have another type of posts, comments, replies for different reasons but with same attributes.

Should I separate these into three tables for each type of posts or should I put it in one table because I have the same attributes in each?

So, what will happen if I want to load data into web application? Is there any difference in complexity for retrieve data between put it in one table or separate it? Or what is the best?

Advertisement

Answer

The answer depends entirely on how you use these tables.

Unifying them will make it easier to write logic that addresses all three types the same way (e.g., granting a badge to a user who accumulated X likes, or deleting all of a user’s content).

Separating them will allow for more flexibility if you want to change these tables in the future (e.g., adding an edit date which could only apply to posts but not to comment).

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement