具有很多属性的数据库表设计
我想知道在这种情况下数据库设计应该是什么样子。
我想到的是每个实体的表格,例如:
Engine
EngineDesign
ElectricalSystem
Drivetrain
etc.
但在我看来,有很多表。我的想法可以吗还是太过分了?
那么传动系统呢?现在我们有 8 个档位,但只要制造商推出不同的产品,它就可以改变。
应该是这样的:
表(列)
DrivetrainId | 1st | 2nd | 3rd | etc.
或
表(行)
DrivetrainId | Gears
1 | 1st
2 | 2nd
3 | 3rd
etc.
I'd like to know how the db design should look like in this case.
What comes to my mind is a table for every entity like:
Engine
EngineDesign
ElectricalSystem
Drivetrain
etc.
But it looks to me as a lot of tables. Is my idea ok or is it excessive?
And what about the Drivetrain? Today we have 8 gears but it can change whenever a manufacturer comes with something different.
Should it be like this:
Table (columns)
DrivetrainId | 1st | 2nd | 3rd | etc.
Or
Table (rows)
DrivetrainId | Gears
1 | 1st
2 | 2nd
3 | 3rd
etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能通过计算表来判断数据库设计的合理性。不存在“表太多”范式或“表不足”范式之类的东西。也不存在“列太多”范式或“列不足”范式之类的东西。
就目前情况而言,为每个变速箱齿轮比设置一列可能仍会达到 5NF。这是因为它没有多个列的值来自同一域,这是一个问题。它有多个列,这些列的值来自同一域并且具有相同的含义,这是一个问题。
显然,8档和1档的含义是不同的。事实上,您可能会认为它们来自不同的领域。我的猜测是 0.67 不是 1 档的有效值,4.85 不是 8 档的有效值。
当它们存储在不同的列中时,
当它们存储为行时,
You can't judge the soundness of a database design by counting tables. There's no such thing as "too many tables" normal form, or "not enough tables" normal form. There's also no such thing as "too many columns" normal form, or "not enough columns" normal form.
As it stands today, having one column for each of the transmission gear ratios might still get you to 5NF. That's because it's not having multiple columns whose values come from the same domain that's a problem. It's having multiple columns whose values come from the same domain and have the same meaning that's a problem.
Clearly, 8th gear and 1st gear have different meanings. In fact, you might consider them to be drawn from different domains. My guess is that 0.67 isn't a valid value for 1st gear, and that 4.85 isn't a valid value for 8th.
When these are stored in different columns,
When they're stored as rows,
我的第一反应是用属性表和汽车表做一些事情(我假设是汽车?)
编辑:请参阅下面的评论 @HLGEM 的解释为什么实体属性值表在本例中不是一个好主意。
My first instinct would be to do something with an Attributes table and a Cars table (I'm assuming cars?)
Edit: See comments below @HLGEM's explanation why an Entity-Attribute-Value table is not a good idea in this example.