Should I create separate tables for users and their profiles for a social network database?
I want to design a database for a social network which will provide profiles for users. Should I use separate tables for users and their profiles or just one table for users and all attributes in i开发者_Go百科t?
If you want to go big, then do a separate one for the users.
Advantage of users and attributes in same table:
- Simpler SQL query.
- If you assumer that you will always need the attributes, then there's one less join.
Advantage of separate tables:
- In real life, you don't always need the attributes.
- When you need to pair other things with users you don't need all the attributes.
If you're going to use a relational database, I would recommend a separate table (normalized, foreign-keys, etc.)
If you are interested in trying one of the document-store databases (e.g., MongoDB, CouchDB, RavenDB), then I would consider first if you normally access attributes when you access a user. If so, then you should place the attributes inside the user as embedded documents.
Good luck!
Keep them separate, Users and Profiles loosely coupled would be helpful in the long run. Profiles can be of communities, groups too not just users, so I suggest keeping them separate.
精彩评论