If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Database for forum

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-09-10, 04:39
Acute Acute is offline
Registered User
 
Join Date: Apr 2009
Posts: 15
Question Database for forum

Hello everyone,
i'm writing my own forum, and now my database has a table for categories, a table for forums (each forum belongs to only one category), a table for members, a table for threads (each thread belongs to only one forum, and each thread has only on member as thread starter), and a table for posts (each post belongs to only one thread and has only one member as poster). Now the questions is:
how "reply to another reply" posts should be organized in the database?
Thnx
Reply With Quote
  #2 (permalink)  
Old 09-09-10, 05:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by Acute View Post
how "reply to another reply" posts should be organized in the database?
add a column to the posts table called in_reply_to

for posts which start a thread, this column is NULL

for posts that reply to another post, put the other post's key into this column as a foreign key
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-09-10, 14:14
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
I'd be more inclined to use a thread/post model than a reverse linked list like r937 suggested. Create one entity for threads, one entity for posts, and a linking entity for threads and posts.

My reaoning is that you almost always traverse from threads to posts, almost never from posts to threads. While r937's suggestion is technically correct, it is relatively inefficient to implement. My suggestion is a tiny bit more complicated in terms of the ERD, but it is a lot more efficient to code/implement.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #4 (permalink)  
Old 09-11-10, 12:37
Acute Acute is offline
Registered User
 
Join Date: Apr 2009
Posts: 15
More details

can you plz describe your idea/method in more details? i'm new in db design so... thnx
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On