Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best table design for application configuration or application option settings?

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 a table with a column for each config parameter and 1 row? With the first I only need to add another row to add a config value, with the second I need to add a column to the table. Are there any issues with either I should take in to consideration? Is one more efficient than the other?

like image 940
Andrew Avatar asked Sep 07 '09 02:09

Andrew


People also ask

What are configuration tables?

Configuration tables are used for Things, Thing Templates, Thing Shapes, and Mashups to store values, such as property values, that do not change often. The most common use of configuration tables is to store credentials and host information for an external resource.

How do I create a database for any application?

When it comes to designing a database for your app, you can choose from 3 types of databases: A relational database is structured to support relationships between pieces of information. Most relational databases use an SQL-like query language that allows you to filter and combine datasets in one result.


2 Answers

For config data, I'd use the key/value structure with a row per configuration entry. You're likely to read this data once and cache it, so performance isn't an issue. As you point out, adding columns each time the set of config keys changes requires a lot more maintenance.

SQL excels at modeling and manipulating arbitrarily large sets of similarly (if not the same) structured data. A set of configuration information really isn't that -- you've got a single row of data OR you've got multiple rows of completely unrelated data. That says you're just using this as a data store. I say skip the SQL data model and go simple.

like image 50
Peter Cardona Avatar answered Sep 19 '22 12:09

Peter Cardona


One more consideration: with a column for each config parameter, you can easily have versions. Each row represents a version*


* of a complete parameter set (as pointed out in a comment by granadaCoder)

like image 39
Luc M Avatar answered Sep 19 '22 12:09

Luc M