I’m using MySQL as my main database for a simple “Social Network” I’m spending a few weeks on.
As with all social networks, the user requires a connection with their friends in order to make it social.
My theory was to either add another column onto my user database and name it connections. There, I would store a string of user id’s separated by a comma, then split them when needed.
Another theory I had was to create a completely new table connections and use two columns “user_1” and “user_2”. The database would then, when searching for friends, would perform a select looking for their id and so on.
The question is though: What would be the most efficient? If I’m to support large numbers of users, is it risky going with option 2?
Some advice would be greatly appreciated,
Thanks!
A normalized structure (option #2) is highly preferable for structuring the type of data that you describe. It will be far more efficient to query a narrow table with two integer columns than to split through an ever-growing list of IDs.
I would suggest reading about the different normalization forms: http://en.wikipedia.org/wiki/Database_normalization (see “Normal Forms”)