user1817467
user1817467

Reputation: 97

Is it better to create a large table in mysql for all blog post comments, or multiple tables for each post?

I am creating a feature on my website akin to a blog. This blog is for posting translated lyrics and will reach about 200 posts.
I am creating a comments database in mysql for this blog. Would it be better to create a table for each blog post to store comments, or one table to store all blog comments and just have a tag that identifies which blog post the comment goes to. Is there any performance implications of the latter?

Upvotes: 1

Views: 417

Answers (3)

Dave
Dave

Reputation: 29141

Create a table for "posts" and a table for "comments".

In your "comments" table, have a field called 'post_id' (or something like that), so you know which post the comment belongs to.

There is no need for more tables than that, and anything beyond is excessive.

As far as speed - if you really meant to say you're going to reach only 200 posts, then you really don't need to be worried too much about speed at this time. When you plan on reaching 2 million posts and comments, then it could be something to think more about, but for now, just design the database well (like mentioned above), make sure it's indexed correctly, and you'll be good to go.

Upvotes: 3

user149341
user149341

Reputation:

One table.

Any database schema which involves an unbounded number of tables (e.g, one table per post) is ill-conceived. Outside of a few very special cases (sharding and partitioning), you should never have multiple tables which represent the same kind of data.

Upvotes: 0

Alnitak
Alnitak

Reputation: 340055

Normal design principles would dictate one table.

Upvotes: 0

Related Questions