在拟议的ER图中消除关系之间的循环
在为简单数据库制作ER模式时,我遇到了以下问题:
- 我在图中获得了一个周期,我不知道它是多余的还是可以以某种方式消除它。
我大规模提出了问题:
- 访问实体记录乘车访问伦敦。该实体包含有关其到达,出发和总访问时间的信息。
- 车辆实体包含有关车辆原产地,二氧化碳排放及其数字板的信息。
- 该实体日期包含与其相关的每周日期的每个日期以及添加任何区域的假期名称的信息。
实体日期
的区域与车辆
区域匹配。实体的entry_date/end_date 访问
匹配到实体date
的日期。最后,将实体车辆
的数字平板匹配到实体的编号plate访问
。这样,我开始提到的周期出现了。
ER图如下:
如果我尚未解释的问题有任何疑问,请随时问我。我欢迎提出改进ER图的建议,以删除周期,或者只是将其保留,就像您认为是正确的那样。
In making an ER schema for a simple database, I have encountered the following problem:
- I get a cycle in the diagram, which I don't know if it is redundant or I could eliminate it somehow.
I present the problem on a large scale:
- The visit entity records visits to London by a vehicle. This entity contains information on their arrival, departure and total visit time.
- The vehicle entity contains information on the vehicle's place of origin, CO2 emissions and its number plate.
- The entity date contains information for each date of the day of the week to which it corresponds and the name of the holiday for any region added.
The region of the entity Date
is matched to the Vehicle
region. The entry_date/end_date of the entity Visit
is matched to the date of the entity Date
. Finally, the number plate of the entity Vehicle
is matched to the number plate of the entity Visit
. In this way, the cycle that I mentioned at the beginning appears.
The ER diagram is as follows:
If there are any questions about the problem that I have not explained, please do not hesitate to ask me. I welcome suggestions for improving the ER diagram, either to remove the cycle or to simply keep it as it is if you think it is correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的两分钱 -
“日期”确实不是实体或表格的好名字。
首先,传达您真正提及的内容太笼统了。
其次,这是大多数通用语言中的保留关键词。您只会给编程带来不必要的麻烦。
您使用“日期”获取假日名称(特定地区)和工作日,对吗?
我的建议是,您只需要在此表中节省假期,因为可以用最常见的编程语言来弄清楚工作日。
此“日期”表只是一个查找表,可以帮助您找出假期,您无需在“日期”和访问之间执行关系,
我还建议您添加区域表来强制执行一致的命名。
这是DB图,我重命名为“日期”到“假期”

这是SQL Server实现 -
My two cents -
"Date" is really not a good name for entity or table.
First, it is too general to convey what you really refer to.
Second, it is a reserved key word in most common languages. You just cause unnecessary trouble for programming.
You use "Date" to get holiday name (for particular region) and week day, right?
My suggestion is that you only need to save holidays in this table because weekday can be figured out in most common programming language.
This "Date" table is just a lookup table to help you find out holiday, you do not need to enforce relation between "Date" and Visit
I'd also suggest you add Region table to enforce consistent naming.
Here is the DB diagram, I renamed "date" to "holiday"

Here is the SQL server implementation -
车辆和日期实体之间的关系是多余的。您仍然可以找到每次访问的日期,从现有关系中完成。如果将ER图转换为DB表,则将更加清楚。
为什么 entry_date 和 exit_date 访问实体的两个属性?这些与日期实体的多对2关系已经考虑了这些。从访问中删除这两个属性。最后,向访问实体添加唯一的ID。
The Relate relationship between Vehicle and Date entity is redundant here. You can still find the dates for each visit a vehicle completed from the existing relationships. If you convert the ER diagram to DB tables, it'll be more clear.
Why are entry_date and exit_date two attributes of the Visit entity? These are already considered by the many-to-2 relationship with the Date entity. Remove these two attributes along with number_plate from Visit. Lastly, add an unique id to the Visit entity.