Search code examples
mysqlxmljsondatabase-designsetting

How to Store Key-Value or One to Many User Settings in database (Xml, Json)?


Should we Keep application key-value settings data in Serialized manner in db like XML or JSON format. e.g. user setting data can be kept in serialized manner in a single nvarchar(2000) column

Or I should keep them as table with columns like BELOW

User ID, Setting Name, Setting Value

  1. 123,AssignedQuiz,Science
  2. 123,AssignedQuiz,Maths
  3. 456,AssignedQuiz,Geo

Solution

  • While storing in serialized manner it is difficult to update a single value in it. Instead You need to update the column every time.
    And if you store in table base it easy to update a single row or retrieve it from table.

    You can define structure as:
    Table:setting
    column(settingid,setting_name,setting_value)

    Table: user_settings
    column(userid,settingid)