Best table design for application configuration or application option settings?

后端 未结 12 2577
说谎
说谎 2020-12-25 10:01

I need to store a series of configuration values in a database. A couple ways I thought of to store them are: a table with 2 colums(name,value) and a row for each pair, or

12条回答
  •  难免孤独
    2020-12-25 10:45

    One disadvantage of using a separate row for each (application) configuration setting (or application option) is that you can't store the setting values in a column with an appropriate data type. Can users enter data with an invalid type? Is that pertinent to your application?

    One benefit of using separate columns is that any code in your DB itself (e.g. stored procedures, functions, etc.) can use a value of the appropriate data-type without first needing to check for invalid values and then convert to the appropriate data type.

    If you're manually deploying changes to your application DB, then yes if you're using an EAV design it is very slightly easier to deploy new configuration settings, but really what's the savings for:

    INSERT Options ( ConfigurationSetting, Value )
    VALUES ( 'NewConfigurationSetting', NewConfigurationSettingValue )
    

    versus:

    ALTER TABLE Options ADD NewConfigurationSetting some_datatype
    
    UPDATE Options
    SET NewConfigurationSetting = NewConfigurationSettingValue
    

提交回复
热议问题