I’m building a social network. For each user, I’m going to expect a lot of information about them. Relationship status, work, hometown, school, etc. I’m sure these profile attributes will grow and grow in the future.
Should I store them all on 1 table, with each attribute as a column?
Or should I create 1 table for “user profile”, with the basic information…and then have other tables (school table, relationship table, work table, etc) Foreign Key to that?
My question is: What is the best practice when separating into multiple tables?
One way to do this is to store the user attributes in a table separate from the main “user” table. This attribute table would have three columns, “user id”, “attribute type”, and “value”. The attribute type can be some identifier that specifies whatever attribute you like (hometown, school, etc).
Once you have this structure set up, adding a new attribute is as simple as adding a new row to the Attribute table describing the attribute. Then fill in the attribute for users in the UserAttribute table as needed. No need for expensive ALTER TABLE operations to add new columns.