数据库设计:与汽车型号或内饰相关?
我正在重新问一个之前在 SO 中删除的问题,因为它不是“编程问题”。希望这篇文章比上一篇文章更加“编程”。
首先,一些定义:
- 型号 -
2011 Nissan Sentra
- 装饰 -
2011 Nissan Sentra LX
一般来说,特定的车辆将有一个列表,例如可用的颜色或设备选项。因此,2011 Nissan Sentra
可能有以下颜色可供选择:
- 黑色
- 白色
- 红色
然后,制造商可能制作了一种仅适用于 2011 Nissan Sentra LX
装饰的特殊颜色:
- 粉红色和黄色圆点
如果我正在构建一个汽车网站,我想在其中捕获此信息,我应该执行以下哪项操作:
- 将颜色与模型相关联?
- 将颜色与装饰相关联?
- 将颜色与模型和装饰相关联?
我的直觉是将其与模型关联起来就足够了。与装饰相关联意味着重复(例如,2011 Nissan Sentra LX
和 2011 Nissan Sentre SE
的颜色均为“黑色”)。试图将颜色与模型和装饰联系起来可能有点矫枉过正。
建议?
I'm re-asking a question that was previously deleted here in SO for not being a "programming question". Hopefully, this is a bit more "programming" than the last post.
First, a few definitions:
- model -
2011 Nissan Sentra
- trim -
2011 Nissan Sentra LX
Generally, a particular vehicle would have a list of, say, available colors or equipment options. So a 2011 Nissan Sentra
may be available in the following colors:
- Black
- White
- Red
Then, the manufacturer may have made a special color only available to the 2011 Nissan Sentra LX
trim:
- Pink with Yellow Polka Dots
If I were building a car website wherein I wanted to capture this information, which of the following should I do:
- Associate the colors to the model?
- Associate the colors to the trim?
- Associate the colors to the model and trim?
My gut feeling is that associating it to the model would be sufficient. Associating to trim would mean duplicates (e.g. 2011 Nissan Sentra LX
and 2011 Nissan Sentre SE
would both have "Black" as a color). Trying to associate colors to model and trim might be overkill.
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据我的评论的要求...
我只会将“颜色”设置为自由格式的文本字段,可能会带有一个预先填充的下拉列表,显示数据库中当前流行的颜色。主要优点是它使您的数据库模式更加简单,并防止您的汽车模型/颜色研究人员发疯。但它也允许进行制造商根本无法提供的定制油漆工作。
As requested in response to my comment...
I would just make 'color' a free-form text field, possibly with a pre-populated drop-down showing current popular colors in the database. The main advantage is that it makes your DB schema much simpler, and keeps your car model/color researchers from going insane. But it also allows for custom paint jobs that aren't available from the manufacturer at all.
,那么您必须构建一个捕获该信息的逻辑模型。 (这有多难?)这意味着你必须对这些事实进行建模。
品牌。)
捕获所有已知的要求是一回事。实施它们是另一回事。一旦您了解了颜色的实际工作原理,
但是,正如博士。菲尔经常说:
简化已知的要求——忽略某些颜色仅适用于一两个装饰包的事实——意味着您设计数据库时故意允许无效数据。您的数据库最终可能会包含有关“粉色带黄色圆点”Nissan Altima 或“Copper”2002 Nissan Sentra 的信息。 (我认为 Nissan 于 2004 年推出了铜。)
所以这是真正的问题。
这始终取决于应用程序。收集有关您的汽车颜色信息的社交媒体网站比销售补漆的公司更能容忍不可能的颜色选择。
then you'd have to build a logical model that captured that information. (How hard was that?) And that means you have to model these facts.
the make.)
Capturing all the known requirements is one thing. Implementing them is another. Once you understand how the colors actually work,
But, as Dr. Phil often says,
Simplifying the known requirements--ignoring the fact that some colors apply only to one or two trim packages--means you design your database to deliberately allow invalid data. Your database might end up with information about a "Pink with Yellow Polka Dots" Nissan Altima, or a "Copper" 2002 Nissan Sentra. (I think Nissan introduced copper in 2004.)
So here's the real question.
That's always going to be application-dependent. A social media site that collected information about your car color would be a lot more tolerant of impossible color choices than a company that sells touch-up paint.
如果存在特殊情况,正如您所说,制造商只为特定装饰提供特殊颜色,例如“带有黄色圆点的粉色”强>“2011 Nissan Sentra LX装饰”
并且您想要存储这些特殊情况,您应该选择第二个选项。
因此,您的关系将是:
1 个制造商生产许多型号
1 个型号有许多装饰
1 个装饰可以有多种颜色,对于 1 种颜色,许多装饰都有它
(因此您需要一个用于此关系的关联表)
有关颜色的附加信息:
一种通用颜色可以由不同制造商命名为多种颜色,并且
一个制造商可以用各种颜色(名称)“洗礼”通用颜色
更清楚地思考,不需要额外的
Manufacturer-Colour
关系:If there are special cases, as you say, where a manufacturer has made a special color only available to a specific trim, like "Pink with Yellow Polka Dots" for the "2011 Nissan Sentra LX trim"
and you want to have those special case stored, you should choose the 2nd option.
So, your relationships would be:
1 manufacturer makes many models
1 model has many trims
1 trim can have many colors and for 1 colour many trims have it
(so you'll need an association table for this relationship)
With additional information about colours:
One GeneralColour can be named as many Colours by different Manufacturers and
one Manufacturer can "baptize" a GeneralColour with various Colour (names)
Thinking more clearly, the extra
Manufacturer-Colour
relationship is not needed:如果同一型号的不同装饰可能有不同的颜色选项(正如您所暗示的),那么您应该将颜色与装饰相关联,否则您将获得不正确/不兼容的信息。又名:如果“粉色带黄色圆点”与“2011 Nissan Sentra”车型相关联,那么您将错误地将其显示为 LX 以外的装饰选项。
If different trims for the same model may have different color options (as you imply) then you should associate the color to the trim, otherwise you will have incorrect/incompatible information. aka If "pink with yellow polka dots" is associated to the "2011 Nissan Sentra" model then you will incorrectly show it as an option for trims other than LX.
您缺少装饰与模型的关联;如果没有这个,我不知道你能否真正正确地完成你的联想。
You're missing the association of the trim to the model; without that, I don't know that you can really properly complete your associations.