chris
chris

Reputation: 2951

User table database best practices

I am wondering what the best practices are for organizing user data.

Should I store all user data per row in one table or should I be cutting it up into smaller chunks and using multiple tables related by primary key?

For example.

To start I would want to record personal info like name, occupation, location etc. Eventually it would be nice to have the option to add usage history. As in how many and which surveys they filled out and which articles they commented on.

While typing this it makes sense to me to have a table for comments a table for username+password, a table for personal info and to keep adding tables as my needs grow...

Would like some confirmation though.

Upvotes: 2

Views: 2406

Answers (2)

Query Master
Query Master

Reputation: 7097

The best practices is optimize your database or you really want to organize users data first you have to go with one to many relation because you can easily track the whole users data with help of join in different table like this

SELECT * FROM user_A a INNER JOIN userdata_B b ON a.id=b.a_id

If users contain multiple records like name name2,occupation1,occupation2,location1,location2 etc so you have to create multiple table and populate this record into these tables because if you populate the whole users data into single table the result take so much execution time

After this apply indexing.......

Upvotes: 1

None
None

Reputation: 5649

If there are going to be one-to-many relations then you should split it up, but for things that are one-to-one you shouldn't. So if the user is going to have multiple addresses, phone numbers, history, friends, etc, then you would have an addresses table (or phone numbers, history, or friends tables) that is tied to the customer's id.

For the username and password you wouldn't need a separate table.

Upvotes: 7

Related Questions