Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sept. 20041 ER-to-Relational Mapping Principles ER-to-Relational Mapping And examples.

Similar presentations


Presentation on theme: "Sept. 20041 ER-to-Relational Mapping Principles ER-to-Relational Mapping And examples."— Presentation transcript:

1 Sept. 20041 ER-to-Relational Mapping Principles ER-to-Relational Mapping And examples

2 Sept. 20042 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 Sept. 20043 1. Create a relation for each strong entity type include all simple attributes choose a primary key Suppose we have: course 1N offered in Section no term meeting course no name credit hours description section

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

5 Sept. 20045 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: course 1N offered in Section no term meeting course no name credit hours description section

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

7 Sept. 20047 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 Sept. 20048 An example showing LoginsHostsAt name Hosts(hostName) this is for the strong entity set. Logins(loginName, hostName, time) At(loginName, hostName, hostName2) Must be the same time At becomes part of Logins, so eliminated!

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

10 Sept. 200410 Department is the better choice since it must participate in the relationship. departmentinstructor chair 11 dept_no dname instr_noiname Department chairdept_nodname If we choose department then instr_no is included as, of course, an FK. Note that instr_no must have a value.

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

12 Sept. 200412 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 studentcourse enroll mn grade Enroll student_noCourse_nograde PK is {student_no, course_no} student_no is a FK course_no is a FK grade is an attribute of Enroll course_no student_no

13 Sept. 200413 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 course 1N offered in Section no term meeting course no name credit hours description section Meeting is a multi-valued attribute

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

15 Sept. 200415 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) semestercourse offers mn room course_no semester_no instructor instr_no p

16 Sept. 200416 We need one relation, offers, with PK of {semester_no, course_no, instr_no} semestercourse offers mn room no course_no semester_no instructor instr_no p Offers course_noinstr_nosemester_noRoom_no

17 Sept. 200417 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 Sept. 200418 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.


Download ppt "Sept. 20041 ER-to-Relational Mapping Principles ER-to-Relational Mapping And examples."

Similar presentations


Ads by Google