Welcome Guest, Not a member yet? Register   Sign In
Multiple blogs on website: one table or many?
#1

[eluser]aidehua[/eluser]
I'm working on a CI website that will allow users to create a blog as part of their user account.

The basic database prototype is pretty straightforward. Let's say (to keep things simple) there is a table for blog_posts and a table for blog_comments.

The question is: would you create a new blog_posts and blog_comments table for each new user's blog?

e.g.
for user 1: blog_posts_1 and blog_comments_1
for user 37: blog_posts_37 and blog_comments_37
for user 38: blog_posts_38 and blog_comments_38
etc.

OR

would you put blog posts for ALL the users in the the SAME set of tables, and just store the user_id in the blog_posts table like this:

blog_posts
----------
id
user_id <-- Just use this field to identify which blog this post belongs to
title
content
date



blog_comments
-------------
id
post_id
comment


I'd be interested in your thoughts on the advantages / disadvantages of the two approaches, especially if you've actually implemented something like this before. Which route did you choose?
#2

[eluser]flaky[/eluser]
If you generate new tables for every user, you might end with hundreds of tables, which isn't very maintainable.
Use one table for all users, with the structure you proposed.
#3

[eluser]aidehua[/eluser]
Thanks Flaky.

What you say is what I thought.

But I thought I'd wait to listen to the wisdom of the crowd first. Sounds like you are the crowd, on this occasion. Wink

Any dissenting voices out there?
#4

[eluser]JanDoToDo[/eluser]
Nope. As above Wink.

Creating multiple tables would be a particularly bad idea for this case as what if 5000 people join and each only post 1 blog? Thats a huge amount of wasted space and overhead that you're creating, especially if they might not even use the table! In terms of speed, MySQL (i presume is what you're using) is very quick and is optimised to execute quickly especially with indexes! Also, what if you wanted/needed to create a new column in each of the tables for, say, language_id? You'd have to go through every single table - unless you use only 1 table that is!

Enjoy!
#5

[eluser]aidehua[/eluser]
Thanks JanDoToDo.

When you put it in the harsh language of numbers, you make the multiple-tables option sound even dumber than I thought.

I agree with you, flaky, and myself. I'll go and think of some more stupid questions now. Wink




Theme © iAndrew 2016 - Forum software by © MyBB