应用程序配置或应用程序选项设置的最佳表设计? [英] Best table design for application configuration or application option settings?

查看:114
本文介绍了应用程序配置或应用程序选项设置的最佳表设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在数据库中存储一系列配置值。
我认为存储它们的几种方法是:一个表有2列(名称,值)和每一对的行,或者一个表,每列配置参数和1行?
第一个我只需要添加另一行添加一个配置值,第二个我需要添加一个列到表。有任何问题,我应该考虑吗?是一个比另一个更有效吗?

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?

推荐答案

对于配置数据,我将使用键/值结构,每个配置项有一行。您可能会读取此数据一次并缓存它,因此性能不是问题。正如你所指出的,每次配置密钥集更改时添加列需要更多的维护。

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在建模和操作任意大集合时相同)结构化数据。一组配置信息确实不是这样 - 你有一行数据,或者你有多行完全不相关的数据。这说明你只是使用它作为数据存储。我说跳过SQL数据模型并简单。

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.

这篇关于应用程序配置或应用程序选项设置的最佳表设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆