0

I'd like to program my own forum for learning purposes and I need some help in planing database structure.

I want to achieve following task:

  1. I want to store members in database
  2. Each user can create new threads
  3. Each thread can be commented by every member

My own approach would be...

  1. Table for members
  2. Table for threads
  3. When user creates new thread, system dinamicly creates new table COMMENTS_THREAD_ID and all comments associated with this thread would be included in this table

Is it good practice to create separate table for comments for each thread? What if site would get popular and there would be thousands of threads daily? Could you suggest structure that would suite this type of scenario?

Thanks

2 Answers 2

3

How about a single SQL table Comment, with fields id, thread_id, member_id and body those fields will be enough to organize your data

I think creating a new SQL table every time a Thread is created is an expensive operation (even if MySQL doesn't impose a hard limit on the number of tables within a database), overall I think RDBMS are more row-centric than anything else (add a new comment row instead of creating a new table)

Sign up to request clarification or add additional context in comments.

Comments

1

No, that is not good practice. You don't need a table for each thread's replies. You can just use a replies table for all of them, if you add a column to it that denotes to which thread each reply belongs.

That's how RDBMS work. Lists of things, put in relation to each other through foreign keys.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.