SQL Database – Saving User Profiles

Architecturedesign-patternssql

So, I got a table UserProfiles in my database, that, similar to C#'s Settings file, holds a property with the appropriate datatype and the specified setting in the profile.

Now each time I add a new setting, I need to update the database, the model and end up rewriting the queries.

I've then thought about changing the table to only contain two columns: Key and Value with a varchar datatype to store the users settings… But what is considered to be best practice in such design-questions?

Is this approach advisable (for example because it needs custom parsing from string to the needed datatype)?

Best Answer

If I understand this question correctly, then, as previously stated by @user61852, this is a database design issue.

Your 'key, value' idea is not a good idea in this instance and will certainly lead to lots of painstaking debugging. You have the full power of a relation model at your finger tips why not use it to its fullest?

From Database fundamentals (a worthwhile read!):

Data modeling defines all the required information from the real world.

You need to think about the Userprofiles table, the data it models and its purpose. If you are extending this table every time you think of something else to add you have not thought about the problem sufficiently.

Related Topic