In many cases, it may be best to split information into multiple related tables, so that there is less redundant data and fewer places to update.
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.
The statement 'select 1' from any table name means that it returns only 1. For example, If any table has 4 records then it will return 1 four times.
You can create a view on a single table to show a subset of the data that the table contains. Compared with the original table, the view can have fewer records and fewer columns, and the columns in the view can have a different order.
I have done this two ways in the past - a single row table and a key/value pair table - and there are positives and negatives to each approach.
The single row option is by far the easiest one to work with. This is because you can store each setting in its correct type in the database and not have to store the types of the settings as well as their lookup keys in code.
One thing I was concerned with using this approach was having multiple rows in the "special" single row settings table. I overcame this by (in SQL Server):
This means that only one row can exist in the table because the bit column has to have a value of 0, but there can only be one row with that value because of the unique constraint.
You should create a table with a column for the information type and information value (at least). This way you avoid having to create new columns every time a new information is added.
A single row will work fine; it will even have strong types:
show_borders bit
admin_name varchar(50)
max_users int
One disadvantage is that it requires a schema change (alter table
) to add a new setting. One alternative is normalizing, where you end up with a table like:
pref_name varchar(50) primary key
pref_value varchar(50)
This has weak types (everything is a varchar), but adding a new setting is just adding a row, something you can do with just database write access.
Personally, I would store it in a single row if that is what works. Overkill to store it in an SQL table? probably, but there is no real harm in doing so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With