How do you structure config data in a database? How do you structure config data in a database? database database

How do you structure config data in a database?


You can expand option 1 to have a 3rd column, giving a data-type. Your application can than use this data-type column to cast the value.

But yeah, I would go with option 1, if config files are not an option. Another advantage of option 1 is you can read it into a Dictionary object (or equivalent) for use in your application really easily.


Since configuration typically can be stored in a text file, the string data type should be more than enough to store the configuration values. If you're using a managed language, it's the code that knows what the data type should be, not the database.

More importantly, consider these things with configuration:

  • Hierarchy: Obviously, configuration will benefit from ahierarchy
  • Versioning: Consider the benefit of being able to roll back to the configuration that was in effect at a certain date.
  • Distribution: Some time, it might be nice to be able to cluster an application. Some properties should probably be local to each node in a cluster.
  • Documentation: Depending on if you have a web tool or something, it is probably nice to store the documentation about a property close to the code that uses it. (Code annotations is very nice for this.)
  • Notification: How is the code going to know that a change has been made somewhere in the configuration repository?

Personally, i like an inverted way of handling configuration, where the configuration properties is injected into the modules which don't know where the values came from. This way, the configuration management system can be very complex or very simple depending on your (current) needs.