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 > Database Server Software > MySQL > Structure Question/Issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-09, 11:04
hisairness hisairness is offline
Registered User
 
Join Date: Dec 2009
Posts: 2
Structure Question/Issue

I'm am building a site where I have users and want to relate them to each other. Like lets say they could become "Friends".

My question is should I have a table called "Friendships" and each time there is a new friendship I would add a row to this database. (Field 1: user, Field 2: Friend 2) or should I have a field in the user table that separates all friends ie(Field Friends: Friend 1, Friend 2, Friend 3).

I know keeping relationships in a comma field goes against a relational database model, but I thought after a certain point (> 500,000 friendships) it would probably process faster than searching the other database?

Any comments on using commas to separate relationships would help. Thanks so much in advance.

Dan
Reply With Quote
  #2 (permalink)  
Old 12-16-09, 11:34
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by hisairness
Any comments on using commas to separate relationships would help.
Use separate fields and just add a new record for each new friend ie
Code:
Create table Friends(
     user_id
     friend_id
)
Using your other method it would be a right pain to say find out who has Fred as a friend or if you wanted to delete Fred from the system and all references to him. Normalising your data makes it easier for you to look after your data. 500k friends??? that's a hell of a Christmas card list.

Mike
Reply With Quote
  #3 (permalink)  
Old 12-16-09, 11:43
hisairness hisairness is offline
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks so much for your response. That makes a lot of sense and solves my issue. You're right deleting a person out of the system would be a nightmare.

I meant 500,000 relationships, but even that seems like it would be quite a bit. haha

Thanks again,
Dan
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