I am trying to develop a database for a website. This website has registered users and these users can befriend other users. Much like any traditional social networking site. Now my problem is, I have to store the friends list of each every user and also his profile information. Each user has his own profile id. Apart from this each user is allowed to create groups for his friends and there is also a status field that says the status of the friendship between the two users.
Now to do this I thought of two solutions:
-
Maintain a table named profiles, in which each user has a profile id and his other profile information and have a global friends table, that has his profile id and his friends profile id. And the other fields would describe, the group, the user has chosen for the particular friend and a status for their friendship and so on.
-
Maintain a table named profiles, in which each user has a profile id and his other profile information like above and have a separate friends table for each user that says something like friends_profileid, and each user has his own friends list which has all other information.
Which of the above two techniques is more appropriate? I am using MySQL Server 5.0 and I also considered using abstract data types and array types, but that’s making the front-end implementation more complex and difficult and cumbersome. While the first technique is increasing the number of rows in a single table at a very high rate, the second technique is increasing the number of tables to be proportional to the number of users? What is more advised? More number of tables or more number of rows?
While the second technique decreases the over head of searching in a single table, what is the overhead of storing the schema again and again? What is the best method for this type of a situation?
SQL was designed to work with a variable number of rows over a fixed set of relationships.
Problems with 1-table-per-user (just off the top of my head):
Conclusion: Please use your RDBMS to its strengths — the world has run on SQL for decades now (at least 2 😉 and most [trivial] problems have been solved numerous times.