Best Way to Handle Meta Information in a SQL Database

Posted by danielhanly.com on Programmers See other posts from Programmers or by danielhanly.com
Published on 2013-10-19T21:32:24Z Indexed on 2013/10/19 22:13 UTC
Read the original article Hit count: 151

Filed under:

I've got a database where I want to store user information and user_meta information.

The reason behind setting it up in this way was because the user_meta side may change over time and I would like to do this without disrupting the master user table.

If possible, I would like some advice on how to best set up this meta data table.

I can either set it as below:

+----+---------+----------+--------------------+
| id | user_id | key      | value              |
+----+---------+----------+--------------------+
| 1  | 1       | email    | [email protected] |
| 2  | 1       | name     | user name          |
| 3  | 1       | address  | test address       |
...

Or, I can set it as below:

+----+---------+--------------------+--------------------+--------------+
| id | user_id | email              | name               | address      |
+----+---------+--------------------+--------------------+--------------+
| 1  | 1       | [email protected] | user name          | test address |

Obviously, the top verison is more flexible, but the bottom version is space saving and perhaps more efficient, returning all the data as a single record.

Which is the best way to go about this?
Or, am I going about this completely wrong and there's another way I've not thought of?

© Programmers or respective owner

Related posts about database-design