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 > Forum Threads Table Design

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-10-08, 09:39
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
Forum Threads Table Design

Hello all,

I am creating a forum. I am designing the tables for the threads and their replies and the relationship between them. Please have a look at these images and give me your thoughts. I have also included the schema.

http://i284.photobucket.com/albums/l...ableDesign.jpg
http://i284.photobucket.com/albums/l...ogicDesign.jpg

Code:
CREATE TABLE  Threads (
       threadID INT NOT NULL AUTO_INCREMENT
     , threadSubject VARCHAR(100) NOT NULL
     , threadContent TEXT NOT NULL
     , link VARCHAR(200)
     , poster VARCHAR(100) NOT NULL
     , PRIMARY KEY (threadID)
);

CREATE TABLE  ThreadReplies (
       replyID INT NOT NULL AUTO_INCREMENT
     , replySubject VARCHAR(100)
     , replyContent TEXT NOT NULL
     , poster VARCHAR(100) NOT NULL
     , PRIMARY KEY (replyID)
);

CREATE TABLE  ThreadsRepliesRelationship (
       threadID INT NOT NULL
     , replyID INT NOT NULL
     , INDEX (threadID)
     , CONSTRAINT ThreadsFK FOREIGN KEY (threadID)
                  REFERENCES  Threads (threadID) ON DELETE CASCADE
     , INDEX (replyID)
     , CONSTRAINT RepliesFK FOREIGN KEY (replyID)
                  REFERENCES  ThreadReplies (replyID) ON DELETE CASCADE
);
1) Is the on cascade correct, i have them in both tables? If a thread reply was deleted would it delete the actual thread - the first post?

Thanks all,
Reply With Quote
  #2 (permalink)  
Old 04-10-08, 09:49
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Nah. A post is attached to only one thread. And a thread start is only the first post in a thread. So at most two tables, maybe even one.

FYI - you can download loads of free forum packages. Why reinvent the wheel?
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 04-10-08, 09:56
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by compsci
1) Is the on cascade correct, i have them in both tables? If a thread reply was deleted would it delete the actual thread - the first post?
actually, you have your cascades in just one table, the ThreadsRepliesRelationship table

if you delete a row in the Threads table, the corresponding rows in the ThreadsRepliesRelationship would be deleted

if you delete a row in the ThreadReplies table, the corresponding rows in the ThreadsRepliesRelationship would be deleted

i agree that there seems to be at least one table too many here
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 04-10-08, 10:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by pootle flump
FYI - you can download loads of free forum packages. Why reinvent the wheel?
i can answer that one...

- because free forum packages are overly complex
- because free forum packages have huge security holes
- because free forum packages don't do what i need
- because free forum packages take too long to understand
- because free forum packages use technology my host doesn't support
- because free forum packages require a different url scheme
- because free forum packages cannot integrate with the rest of my site
- because free forum packages suck the big one111!!1!1

helps?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 04-10-08, 10:02
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
Quote:
Originally Posted by r937
actually, you have your cascades in just one table, the ThreadsRepliesRelationship table

if you delete a row in the Threads table, the corresponding rows in the ThreadsRepliesRelationship would be deleted

if you delete a row in the ThreadReplies table, the corresponding rows in the ThreadsRepliesRelationship would be deleted

i agree that there seems to be at least one table too many here
That seems fine to me so far, but how can i add one more cascade so that when a row in the Threads Table is deleted all corresponding rows in the ThreadReplies is deleted?

Is there a better way than the approach i have taken so far?
Reply With Quote
  #6 (permalink)  
Old 04-10-08, 10:05
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
lol i was going to reply with only a few reaons, but all mine are in r937's post!

The main reason for me is that they are not that customizable - i want a really light weight forum. A really really simple one. Plus i like doing it myself so that if something does go wrong i know where to look.
Reply With Quote
  #7 (permalink)  
Old 04-10-08, 10:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by compsci
That seems fine to me so far, but how can i add one more cascade so that when a row in the Threads Table is deleted all corresponding rows in the ThreadReplies is deleted?
you cannot
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 04-10-08, 10:29
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
Quote:
Originally Posted by r937
you cannot
Do i have to remove the table ThreadsRepliesRelationship for that to work?

Is that a good idea or is there a better approach to this threads table design?
Reply With Quote
  #9 (permalink)  
Old 04-10-08, 10:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
yes, i would remove it, as poots suggested

the reason is, a reply typically belongs to only one thread

add threadID to the ThreadReplies table and drop the ThreadsRepliesRelationship table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 04-10-08, 10:59
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
Oh lol - I didn't even think of that! Thanks guys!
Reply With Quote
  #11 (permalink)  
Old 04-10-08, 16:22
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Quote:
Originally Posted by r937
helps?

No. I know packages that don't tick most if not all of those boxes. The code is totally configurable. You can get forums written in pretty well any language under GPL. Different URL scheme - you not got a text editor? How can it take longer to use a WYSIWYG forum tool than to build one from scratch? Add loads of MODs, cummunity support, 10s to 10000s of reference sites.

If you want to do one to learn or for the sake of it then fair enough. But I think that of almost all the packages you might build yourself vs get for free I reckon building a forum represents one of the worst ROIs on your time there is.

So - NAH!
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #12 (permalink)  
Old 04-10-08, 22:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by pootle flump
No. ... [snip a bunch of crap] ... So - NAH!
url(s) of the forum(s) you implemented, please
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #13 (permalink)  
Old 04-11-08, 02:37
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
All internal - there will be loads eventually but all closed to riff raff. I've been evaluating packages (snitz, phpBB, Yet Another Forum). Thread recently posted in the mod forum
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #14 (permalink)  
Old 04-11-08, 02:38
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Oh - beg your pardon - links to forums:
www.snitz.com
www.yetanotherforum.net
www.phpbb.com
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #15 (permalink)  
Old 04-11-08, 07:41
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
hey, that's great news, poots, i may need to talk to you about your experiences for a project i'm working on

no vBulletin?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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