数据库表只有1或2个可选字段...分成多个表? [英] Database table with just 1 or 2 optional fields... split into multiple tables?

查看:236
本文介绍了数据库表只有1或2个可选字段...分成多个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我设计的数据库中,有一个相当中心的表格表示出售或出售的东西。它区分个人销售(如eBay)和适当公司的销售。这意味着字面上一个或两个字段对于这两种情况都不是同等适用的。例如,一个字段仅在一种情况下使用,另一个字段在一种情况下是可选的,但在另一种情况下是强制性的。
如果有更多的专业,那么拥有一个核心表,然后两个表与具体情况相关的表将是明智的。但是在这里,创建两个表仅仅包含一个字段加上对核心表的引用,似乎在审美上是不好的,对查询设计器和数据库软件来说是痛苦的。



你认为?通过拥有一个具有削弱约束的单个表来略微缩小规则,这意味着数据库不能100%防止添加不一致的数据(以非常有限的方式) - 或者我吸吮它并创建愚蠢的1场表格?

解决方案

我认为拥有这些领域的选择不会在今天伤害你,而且我会选择对于。只要记住,随着数据库的发展,您可能需要做出重构到2个独立表格的决定(如果您需要更多的字段)


In a DB I'm designing, there's one fairly central table representing something that's been sold or is for sale. It distinguishes between personal sales (like eBay) and sales from a proper company. This means there is literally 1 or two fields which are not equally appropiate to both cases... for instance one field is only used in one case, another field is optional in one case but mandatory in the other. If there were more specialty it would be sensible to have a core table and then two tables with the fields relevant to the specific cases. But here, creating two tables just to contain like one field plus the reference to the core table seems both aesthetically bad, and painful to the query designer and DB software.

What do you think? Is it ok to bend the rules slightly by having a single table with weakened constraints - meaning the DB cannot 100% prevent inconsistent data being added (in a very limited way) - or do I suck it up and create dumb-looking 1-field tables?

解决方案

I think the choice of having these fields is not going to hurt you today and would be the choice I would go for. just remember that as your database evolves you may need to make the decision to refactor to 2 separate tables, (if you need more fields)

这篇关于数据库表只有1或2个可选字段...分成多个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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