Table design for user's information as well as login credentials?

Prix picture Prix · Jun 29, 2010 · Viewed 14.8k times · Source

Initially I would like to ask you to forget about hashing passwords or w/e related to passwords, this question is not related to securing passwords, etc and I do know/understand how this should be done.

What is the best approach to store the data in question, considering performance on read/write - to build one or more tables?

Single table, for example:

Table users: id, username, password, hash, email, group, access, address, phone, parents, ts_created, ts_update

Multiple tables, for example:

Table users: id, username, password, hash, email, group, access, ts_created, ts_update

Table user's information: id, user_id, address, phone, parents, ts_created, ts_update

What if your user's information fields may grow along the time - how should you deal with it ?

For example new fields: birthday_date, comments, situation

Will having 2 tables be slower on queries than having a single table ?

If having multiple tables in this case is only for maintaining a good design with separated data, does that mean it is not useful at all for performance reasons ?

If you want real sql examples let me know and I will scrap something to update this.

Answer

BenW picture BenW · Jun 29, 2010

You may need even more tables depending on the data your going to store:

  1. What if you use a password policy in the future where a user cannot re-use a previously used password?
  2. Can a user have more than one email?
  3. Can a user belong to more than one group?
  4. Can a user have more than one phone number?
  5. Only one parent? Or two? Is the parent in the system? What information about the parent do you store?

Storing thinks like this may be worth to store in its own individual table, which means that in the future it should be a lot easier to maintain. You need to think of how the system will change. As for performance, as already outlined it shouldn't be a problem as long as you create the correct indexes, and use the database correctly.