简体   繁体   English

您应该为固定选项创建单独的表吗?

[英]Should you create separate tables for fixed options?

As shown below, in multiple places in my DB Design I am creating tables for "options" if you will. 如下所示,在我的数据库设计中的多个位置,如果您愿意,我正在为“选项”创建表。 Example, RFP Stages. 例如,RFP阶段。 Which would hold things like "Complete", "Bidding", etc. 哪个会包含“完成”,“竞标”等内容。

I'm doing this because it was recommended to me at one point in a question that was deleted. 我这样做是因为在一个被删除的问题中我被推荐给了我。 Is this the proper way to do this? 这是正确的方法吗? Or should I just store these options as text, given there are only 5 or so possibilities? 或者我应该将这些选项存储为文本,因为只有5种左右的可能性?

在此输入图像描述

在此输入图像描述 在此输入图像描述

Additional fields 附加字段

If your list of possible values such as rfp_stage involves more than just a name, then you definitely want a look-up table added to your design. 如果您的可能值列表(例如rfp_stage涉及名称,那么您肯定需要在设计中添加一个查找表。 For example, to track a color used for "Complete" and another color for “Bidding”, then you need a second field color along with name on the rfp_stage look-up table. 例如,要跟踪用于“完成”的颜色和“出价”的另一种颜色,则需要第二个字段color以及rfp_stage查找表上的name

Single field 单场

If the name of each RFP stage is the only value, no such additional items such as color discussed above, then you may want to use a string column without any lookup table. 如果每个RFP阶段的名称是唯一的值,没有上面讨论的颜色等附加项,那么您可能希望使用不带任何查找表的字符串列。

You could enforce a list of possible values in your app(s). 您可以在应用程序中强制执行可能值的列表。

As a backup to the app's enforcement, if you are using a powerful database system such as Postgres , you can define a domain of possible values and require the field to always have a value in that domain. 作为应用程序执行的备份,如果您使用强大的数据库系统(如Postgres) ,则可以定义可能值的域 ,并要求该字段始终在该域中具有值。 Trying to add or update a row with an unexpected value will fail, with an error thrown by the database engine. 尝试添加或更新具有意外值的行将失败,并且数据库引擎会抛出错误。

Handling changes to value 处理价值变化

Then again, if there is any possibility of the names of any stage changing, such as “Bidding” changing to “Out for bid” (same meaning, different wording), then a look-up table is useful as a single place to update the wording. 然后,如果任何阶段的名称有可能发生变化,例如“出价”更改为“出价”(相同的含义,不同的措辞),则查找表可用作更新的单个位置措辞。 No need to perform a mass update of values across many rows. 无需跨多行执行大量的值更新。

Internationalization 国际化

Similarly, if you need to localize the display of each RFP stage, say to show “Complete” and “Bidding” in French or Japanese, then you need to add the look-up table. 同样,如果您需要本地化每个RFP阶段的显示,例如以法语或日语显示“完成”和“出价”,则需要添加查找表。 You'll likely have yet another look-up table to hold localization strings, but that's outside the scope of this Answer. 您可能还有另一个查找表来保存本地化字符串,但这超出了本答案的范围。 Search Stack Overflow and perhaps DBA Stack Exchange for more info. 搜索Stack Overflow以及DBA Stack Exchange以获取更多信息。

Enum 枚举

Lastly, some people might use an enum in the database as a stand-in value to represent each possible value. 最后,有些人可能会使用数据库中的枚举作为替代值来表示每个可能的值。 For example, “1” for “Complete”, “2” for “Bidding”, and so on. 例如,“完成”为“1”,“出价”为“2”,依此类推。 I generally avoid this approach myself as it makes reading the data from the rows awkward and inconvenient. 我自己通常会避免使用这种方法,因为它会使行中的数据读取不方便且不方便。

Context 上下文

As with many design decisions, there is no clear-cut golden rule. 与许多设计决策一样,没有明确的黄金法则。 Context matters. 环境很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果您不构建数据仓库,应该如何将维度表与事实表分开? - How should you separate dimension tables from fact tables if you are not building a data warehouse? 我应该将“消息”分成两个表格吗? - Should I separate “message” into 2 tables? 当我有固定数量的字段可能值时,是否应该在 MySQL 中创建一个单独的表? - Should I create a separate table in MySQL when I have fixed number of possible values for a field? 您如何区分结果? 将一组行分成单独的表? - How do you separate results? Separate a group of rows into separate tables? 我应该有单独的表格还是整合数据? - Should I have separate tables or integrate the data? 我应该把一张桌子分成两个单独的桌子吗? - Should I split a table into 2 separate tables? 我应该将实际数据和预测数据分成 2 个表吗? - Should I separate Actual and Forecast data into 2 tables? 您应该在SSRS中分离报表部件吗? - Should you separate Report Parts in SSRS? 我应该为具有固定键的分区创建索引吗? - Should I create an index for partition with fixed key? 您应该通过表格或 Mysql 中的计算进行扩展吗? - Should you scale through tables or computation in Mysql?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM