Topic: ER Diagram

Question 01

Construct an E-R diagram for a car insurance company whose customers own one or more cars each. Each car has associated with it zero to any number of recorded accidents.
Each insurance policy covers one or more cars, and has one or more premium payments associated with it.
Each payment is for a particular period of time, and has an associated due date, and the date when the payment was received.

Answer: :::danger One Possible E-R diagram is shown in Figure 6.101.
Payments are modeled as weak entities since they are related to a specific policy.
Note that the participation of accident in the relationship participated is not total,
since it is possible that there is an accident report where the participating car is unkown.
image.png
image.png ::: TUR05 CISC3000 Tutorial 05 - 图3```sql insurance company:

car (car_id, accident, foreign customer_id) customer (customer_id, car_id) policy (policy_id ,car, premium_amount) premium (premium_amount, time, date_due, date_received, policy_id)

create table customer ( customer_id )

  1. <a name="KzWy0"></a>
  2. ## Question 02
  3. Explain the distinctions 區別 among the terms primary key, candidate key, and superkey.
  4. Answer:
  5. :::danger
  6. A superkey is a set of one or more attributes that, taken collectively, allows us to identify uniquely an entity in the entity set. A superkey may contain extraneous attributes. If K is a superkey, then so is any superset of K.
  7. A superkey for which no proper subset is also a superkey is called a candidate key.
  8. It is possible that several distinct sets of attributes could serve as candidate keys.
  9. The primary key is one of the candidate keys that is chosen by the database designer as the principal means of identifying entities within an entity set.
  10. :::
  11. ![](https://cdn.nlark.com/yuque/0/2020/svg/456757/1590723492305-648940b4-5ee2-48e2-8272-91f197042b89.svg)
  12. Candidate Keys 候選鍵:<br />One or any attributes that can uniquely identify a record. It has unique one and minimum one.
  13. Primary Keys 主鍵:<br />From Candidate Keys find one specific one key that can be representative most. It is also for sort.
  14. Superkey 超鍵:<br />Any candidate key with any attributes in the table.
  15. ```sql
  16. For example:学生资料表
  17. (student_id, student_no, student_name, student_depid)
  18. 其中:
  19. student_id表示学生身分证字号
  20. student_no表示学生学号
  21. student_name表示学生姓名
  22. student_depid表示学生的科系代号
  23. 则:
  24. Candidate Key :
  25. 就可以是 {student_id} 或者 {student_no}.
  26. Primary Key :
  27. 从Candidate Key挑选一个,至于挑选哪一个,就看你的系统特性.
  28. Alternate(Secondary ) Key :
  29. 就是没被挑中当成Primary Key的其他Candidate Key,
  30. 例如,如果挑选 {student_id}当成主键,Alternate(Secondary ) Key 就是{student_no}
  31. Super key:
  32. 就可以是 {student_id}、{student_no}、 {student_id, student_no}、{student_id, student_name}、
  33. {student_id, student_depid} ... 等等,都符合唯一性的条件。
  34. 若存在科系资料表depentment (depid, dep_name),
  35. 而且depid当成科系资料表的主键,学生资料表的 student_depid就是Foreign Key。

Question 03

Construct an E-R diagram for a hospital with a set of patients and a set of medical doctors.
Associate with each patient a log of the various tests and examinations conducted.

Answer:

:::danger It shows a simple E-R diagram for the hospital in the below figure.
Although the diagram meets the specifications of the question, a real world hospital would have many more requirements, such as tracking patient admissions and visits, including which doctor sees a patient on each visit, recording results of tests in a more structured manner, and so on.
image.png
image.png :::

TUR05 CISC3000 Tutorial 05 - 图6