[eluser]jedd[/eluser]
[quote author="TornUp" date="1275832830"]
I was wondering if you was able to help me in regards to designing a DB layout for a social networking site.
[/quote]
First thoughts -
o email should be in a separate table, if you ever want the ability to have more than one email address for a given user. Most sites do not, but sometimes this is useful
o user table PK should be 'id' not 'user_id'
o stick with singular or plural table names - I prefer and advocate singular - but just pick one and be consistent with it, otherwise it will confuse the shinola out of you very quickly
o do not de-normalise unless you have a spectacularly good reason to - f.e. counts for number of PM's sent - just generate that (count() from pm where pm.from = user.id) - that kind of thing. If you find that your DB can't cache this stuff adequately well for you,
then you alter your user table to keep an aggregate column in there for this information - same applies for # of logins, pm's received, and so on.
o do not limit yourself to a boolean
user_active flag - have a status flag in the user table, that can be set to inactive, banned, pending, locked, etc.
o things like
send_pm can get confusing - I saw a good approach a while ago and have since adopted it that all booleans start with 'is_' - so 'is_pm_able' (for example). The idea is that 'send_pm' would be ambiguous later, but if you have something like 'is_...' you can spot immediately that it's a boolean. Similarly 'when_' for all date fields. Again .. modify to taste, but have a think about the benefits.