具有重复属性的 Mysql 表
我正在设计一个简单的经销商网站,其中涉及多个功能。用户可以登录并发布有关汽车的帖子。
帖子可以针对新车/二手车:
`new_posts` database has the following fields
- id
- title
- price_from
- price_to
- date_submitted
`used_posts` database has the following
- id
- title
- price_from
- price_to
- year_from
- year_to
- date_submitted
请注意属性是如何重复的。我经常遇到这样的问题,想知道解决这个问题的最佳方法是什么。我对数据库规范化的了解一般,但我可以使用我能得到的任何帮助。
谢谢
Im designing a simple dealership site that involves several features. Users can sign on and make posts for cars.
Posts can either be for New Cars/ Used Cars:
`new_posts` database has the following fields
- id
- title
- price_from
- price_to
- date_submitted
`used_posts` database has the following
- id
- title
- price_from
- price_to
- year_from
- year_to
- date_submitted
Notice how there is duplication of the attributes. I run into issues like this often and wanted to know what is the best way to deal with this. I have average knowledge of database normalization but i can use any help i can get.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有很多选项,但有两个核心思想:
车辆
的字段,这就是您的基表。然后您可以创建其他表 -truck
、van
、SUV
、new
、used
- 包含字段。然后,您需要桥表将它们连接回您的基本vehicle
表。第一个选项很容易实现,但难以扩展。第二个更复杂,但扩展更容易。
就我个人而言,我会合并这两个表。它可能不会给任何 DBA 留下深刻的印象,但从应用程序的角度来看它很实用。
There are many options, but two core ideas:
vehicle
and that's your base table. Then you could create other tables -truck
,van
,SUV
,new
,used
- that contain fields. You'd then need bridge tables to join them back to your basevehicle
table.The first option is easy to implement, but difficult to scale. The second is more complex, but scales easier.
Personally, I'd merge the two tables. It may not impress any DBAs, but it's practical from an application perspective.
像这样的事情怎么样?
How about something like this?