1 / 18

ER-to-Relational Mapping Principles

ER-to-Relational Mapping And examples. ER-to-Relational Mapping Principles. General process 1 . Create a relation for each strong entity type 2 . Create a relation for each weak entity type 3 . For each binary 1:1 relationship choose an entity and include the other’s PK in it as an FK

kostya
Télécharger la présentation

ER-to-Relational Mapping Principles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ER-to-Relational Mapping And examples • ER-to-Relational Mapping Principles

  2. General process 1. Create a relation for each strong entity type 2. Create a relation for each weak entity type 3. For each binary 1:1 relationship choose an entity and include the other’s PK in it as an FK 4. For each binary 1:n relationship, choose the n-side entity and include an FK with respect to the other entity. 5. For each binary M:N relationship, create a relation for the relationship 6. For each multi-valued attribute create a new relation 7. For each n-ary relationship, create a relation for the relationship

  3. 1. Create a relation for each strong entity type • include all simple attributes • choose a primary key Suppose we have: name term course no Section no offered in 1 N course section description credit hours meeting

  4. We create a relation for Course - four attributes, course_no is the PK. name term course no Section no offered in 1 N course section description credit hours meeting Course Course_no name credit_hours description

  5. 2. Create a relation for each weak entity type • include primary key of owner (an FK) • Owner’s PK + partial key become the PK Suppose we have: name term course no Section no offered in 1 N course section description credit hours meeting

  6. We create a relation for Section name term course no Section no offered in 1 N course section description credit hours meeting Section • PK is {course_no, section_no}. • course_no is an FK. • meeting is not a simple attribute, so it’s not included. Course_no Section_no Term

  7. How to handle the identifying relationship in which a weak entity set is involved? • Relation for a weak entity set must include multiple attributes for its complete key (including those belonging to its identifying entity sets), as well as its own, partial key attributes. • An identifying (double-diamond) relationship is redundant and yields no relation.

  8. Must be the same At becomes part of Logins, so eliminated! An example showing name name Logins At Hosts time Hosts(hostName) this is for the strong entity set. Logins(loginName, hostName, time) At(loginName, hostName, hostName2)

  9. instr_no iname dname dept_no chair 1 1 department instructor 3. For each binary 1:1 relationship choose an entity and include the other’s PK in it as an FK. • There are two choices here • choose department, or • choose instructor • Which is the better choice?

  10. Department is the better choice since it must participate in the relationship. instr_no iname dname dept_no chair 1 1 department instructor If we choose department then instr_no is included as, of course, an FK. Note that instr_no must have a value. Department dept_no dname chair

  11. 4. For each binary 1:n relationship, choose the n-side entity and include an FK w.r.t the other entity. instr_no iname dname dept_no employs 1 N department instructor We must choose instructor We end up with: Note that Step 1 would lead to the instructor relation - we have now augmented instructor with the dept_no attribute. instructor • PK is instr_no • dept_no is an FK instr_no iname dept_no

  12. 5. For each binary M:N relationship, create a relation for the relationship • include PKs of both participating entities and any attributes of the relationship • PK is the catenation of the participating entities’ PKs student_no course_no grade m n student course enroll Enroll • PK is {student_no, course_no} • student_no is a FK • course_no is a FK • grade is an attribute of Enroll student_no Course_no grade

  13. 6. For each multi-valued attribute create a new relation • include the PK attributes of the entity type • PK is the PK of the entity type and the multi-valued attribute name term course no Section no offered in 1 N course section description credit hours meeting Meeting is a multi-valued attribute

  14. Create a relation for meeting Section was created because of Step 2 - its PK is {course_no, section_no} meeting Meeting • PK is {course_no, section_no, meeting}. • Meeting is an all-key relation. course_no section_no meeting

  15. 7. For each n-ary relationship, create a relation for the relationship • include PKs of all participating entities and any attributes of the relationship • PK may be the catenation of the participating entity PKs (depends on cardinalities) semester_no course_no room m n semester course offers p instructor instr_no

  16. We need one relation, offers, with PK of {semester_no, course_no, instr_no} semester_no course_no room no m n semester course offers p instructor instr_no Offers course_no instr_no semester_no Room_no

  17. Another perspective to see how to map E/R Diagrams to Relations • Entity sets become relations with the same set of attributes. • Regular entity set • Weak entity set – need help • Relationships • Identifying relationship • eliminated, actually merged to weak entity set relation. • Regular relationship • become relations whose attributes are only: • The keys of the connected entity sets. • Attributes of the relationship itself.

  18. Combining Relations for binary relationship • Then to combine the relation for an entity-set E with the relation R for a many-one relationship from E to another entity set. • Of course, the combination (merging) is applicable to one-one relationship. • To avoid null values, we chose full participating entity set relation to add a foreign key referencing the opposite entity set.

More Related