Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to design application settings table in database

Tags:

sql

I want ot create database table in which I can store application settings. Which of the two table designs is better:

  1. Store the settings in a column and one row for key - something like this:

enter image description here

  1. Store the settings in only two rows - something like this:

enter image description here

Which of the two is more appropriate for storing application settings?

Best wishes

like image 268
Peter Penzov Avatar asked Mar 10 '12 14:03

Peter Penzov


People also ask

What is a configuration table in database?

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.

What is table design in SQL?

The Table Designer is a visual tool where you design and visualizes database tables. Use the SQL Server Management Studio (SSMS) Table Designer to create, edit, or delete tables, columns, keys, indexes, relationships, and constraints.


1 Answers

Use the second method. Obviously it is far more scalable. You will never need to add additional columns when you need to add more options.

I would only advocate the first method if the options are very limited and fixed, and all have different data types. That's an area where the two differ considerably - if you have a big mix of numeric and character columns, you have really no choice with the second option but to store them all as VARCHAR. However, for a settings table that will have a very limited number of rows and won't be subject to a lot of INSERT and UPDATE, that probably isn't a big issue.

You would not want to use the second method for a regular table (not storing mostly static application settings) that needs to be highly accessible, or used for calculations for example, where you would constantly need to be type casting values to manipulate them.

For static data infrequently accessed or modified, the second method works well though.

like image 115
Michael Berkowski Avatar answered Oct 07 '22 01:10

Michael Berkowski