I'm developing an app and it requires me to design the database. I'm wondering what'd be more optimal design in following scenario:
Approach 1:
Have one user table with all the user fields viz.
id | uid | username | first_name | last_name | profession
OR
Approach 2:
Table I:
id | uid | username
Table II:
uid | key | value |
1 | 'first_name' | John
2 | 'last_name' | Donald and so on
The first approach favours more columns to store the user data, while the second approach relies on multiple tables and stores data into several rows for each user.
The second approach would mean that for each user, the user_meta table will have large number of rows while approach #1 will be more compact.
Questions:
- Which approach is better in terms of performance and speed of queries?
- Is there any rule for designing the database where you've to decide whether to store the data in rows vs columns?