database - 绘制 ER 图的令人困惑的场景

标签 database relational-database entity-relationship erd

大家好,堆栈溢出成员,

我正在关系数据库模块中学习实体关系图。我们已经了解了 ER 图足以创建实体,识别每个实体的属性,包括主键、外键、实体之间的关系和基数约束。

我们得到了考文垂大学的官方场景,要求根据该场景绘制 ER 图。问题是;没有一个学生得到正确的答案(对 ERD 不满意),甚至导师和老师也对此感到困惑。我按照我的理解回答了,但我对我的回答不满意。

这是场景:

Consider the following scenario modeling project management activities in an organization.

A car sales company offers to its customers the option of purchasing a car using repayment schemes of over 1 year, 2 years, 3 years, 4 years or 5 years.
A customer may purchase one or more cars under the scheme. When a customer purchases a car, he or she gets to choose one of the repayment scheme options for each purchase or may pay the whole amount in one go, meaning a repayment scheme option may be selected by one or more customers or may not be selected at all. A customer will have a unique customer number, a name, an address, and a phone number. A repayment scheme option will have a unique repayment scheme number, a name and the number of years for repayment. A car will have a unique car code, a make, a model, year of manufacture and a price.

The company pays commission on sales of cars to its salespeople and therefore it will also keep information about each sale which will include a unique sales ID and commission to be paid on that sale. The company will also want to know who made the sales and the car involved in that transaction so that the commission can be determined. A salesperson will have a unique salesperson ID, a name, a phone number and an email address.

这是要求/问题: 为上述给定场景构建实体关系图 (ERD)。识别所有实体, 每个实体的属性,包括主键、外键、实体之间的关系 基数约束。陈述支持您的设计所需的任何假设。

我的回答:

Car sale database diagram

我想知道我的答案是否正确?如果不是/正确答案是什么?

谢谢

最佳答案

欢迎来到 StackOverflow。感谢您展示自己的答案。

对您的答案的反馈:

您在使用按键时遇到了一些困难。您的外键不需要包含在主键中。

您将每个客户与一个 re payment_scheme_number 相关联,这意味着客户只能为他的所有购买选择一种还款方案。我读到作业说他可以在每次购买时选择一个方案:

When a customer purchases a car, he or she gets to choose one of the repayment scheme options for each purchase

通过将每辆车与客户和销售人员相关联,一辆车只能销售一次,并且销售与所售汽车之间没有任何关系。

您也没有区分实体和关系。外键约束不是关系,ER 中的关系被实现为表(或 ER 术语中的关系关系,而不是实体关系)。外键约束只是完整性约束,以确保您不会关联不存在的值。

我的回答:

Car sale ER diagram

我使用 Chen 的表示法,因为它区分实体和关系。外键约束由实体和关系之间的线表示。

直接实现,物理模型将如下所示:

Car sale physical model

正如您所看到的,这种格式并不指示哪些表代表实体或关系,尽管可以通过查看表的主键来确定。通过使用相同行列式对关系进行非规范化可以获得更有效的设计:

Car sale physical model 2

关于database - 绘制 ER 图的令人困惑的场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37318203/

相关文章:

MySQL 二进制协议(protocol)准备响应

php - 基于引用表值连接表

mysql - 从 Travel_point 表中获取 tp.address_from 和 tp.address_to

database-design - 设计数据库以保存不同的元数据信息

sql-server - 如何使用 Microsoft SQL Server Management Studio 生成数据库的实体关系 (ER) 图?

php - Laravel 查询结果与子数组没有 Eloquent

database-design - 将现实世界实体建模到数据库中的最简单方法

java - 从 Assets 文件夹中删除数据库文件

database - 规范化和主键

database - 关系数据库设计: One-to-many connection - Is storing a customer ID as part of an order ID too redundant?