Using facebook as an example, each member have a set of 'friends'.
In the database, do you have a table with a field 'memberID' and another field for 'friendID'? This seems very brute-force and inefficient in terms of redundant data (i.e. if member has 10 friends, that's 10 entries).
---OR---
you could have an entry per member, and a field for friendIDs which could be a comma-separated string or something.. this seems more efficient in the database but would dramatically increase processing time to parse the string.
I would choose option 1).
Ideas? Opinions? Alternate options??
Thanks in advance.
Database design for social network?christian myspace
Option 1) is the way to go. You should add foreign key constraints to ensure consistency.
Database design for social network?wrestlers myspace myspace.com
You would have a "Members" table:
MemberID LastName FirstName
-------------- -------------- ---------------
10000000 Brown Kwame
10000007 Bryant Kobe
10000008 Jordan Michael
A friend is also a member.
Next, create a "Friends" table:
MemberID FriendID
-------------- ------------
10000000 10000007
10000000 10000008
The MemberID is the original member, and the FriendID column contains the MemberIDs of the Friends
Now check the Results
SELECT FriendID FROM Friends WHERE MemberID='1000000'
FriendID
-------------
10000007
10000008
This way, you normalize your tables. This way a member can have as many friends as possible and you don't have repeating fields in your tables.
That is going to be a tough decision, may be you can contact a database expert at website like http://oktutorial.com/ .
No comments:
Post a Comment