Relational Mappingالتحويل إلى النموذج العلائقي
مقدمة الفصل
ماذا ستتعلم في هذا الفصل
- The seven-step algorithm that converts the basic ER constructs into relations.
- Mapping strong and weak entity sets, 1:1, 1:N and M:N relationship sets, multivalued attributes and n-ary relationship sets.
- The correspondence between ER and relational models.
- Step 8: the four options (8A–8D) for mapping specialization or generalization.
أقسام الفصل
- 1The seven-step ER-to-relational algorithmخوارزمية الخطوات السبع
- 2Steps 1 and 2: strong and weak entity setsالخطوتان 1 و2: الكيانات القوية والضعيفة
- 3Step 3: binary 1:1 relationship setsالخطوة 3: علاقات 1:1
- 4Step 4: binary 1:N relationship setsالخطوة 4: علاقات 1:N
- 5Steps 5 and 6: M:N relationships and multivalued attributesالخطوتان 5 و6: علاقات M:N والصفات متعددة القيم
- 6Step 7: n-ary relationship setsالخطوة 7: العلاقات النونية
- 7Steps 5 and 6: M:N relationships and multivalued attributesالخطوتان 5 و6: علاقات M:N والصفات متعددة القيم
- 8Step 8: mapping specialization or generalizationالخطوة 8: تحويل التخصيص أو التعميم
تلميح: استخدم أسهم لوحة المفاتيح للتنقل بين الشرائح.
The seven stepsالخطوات السبع
The seven-step ER-to-relational algorithm
Converting the basic ER constructs into relations (slide 2)
- 1
Step 1: regular (strong) entity sets
- 2
Step 2: weak entity sets
- 3
Step 3: binary 1:1 relationship sets
- 4
Step 4: binary 1:N relationship sets
- 5
Step 5: binary M:N relationship sets
- 6
Step 6: multivalued attributes
- 7
Step 7: n-ary relationship sets
The COMPANY ER schemaمخطط COMPANY
The seven-step ER-to-relational algorithm
| Entity set | Attributes as drawn |
|---|---|
| EMPLOYEE | Ssn (underlined), Name (composite: Fname, Minit, Lname), Bdate, Address, Sex, Salary |
| DEPARTMENT | Name and Number (both underlined), Locations (double oval: multivalued), NumberOfEmployees (dashed oval: derived) |
| PROJECT | Name and Number (both underlined), Location |
| DEPENDENT (double rectangle: weak) | Name (dashed underline: partial key), Sex, BirthDate, Relationship |
| Relationship setمجموعة العلاقة | Betweenبين | Ratioالنسبة | Linesالخطوط |
|---|---|---|---|
| WORKS_FOR | EMPLOYEE (N) and DEPARTMENT (1) | N:1 | double lines on both sides |
| MANAGES (attribute StartDate) | EMPLOYEE (1) and DEPARTMENT (1) | 1:1 | EMPLOYEE single, DEPARTMENT double |
| CONTROLS | DEPARTMENT (1) and PROJECT (N) | 1:N | DEPARTMENT single, PROJECT double |
| WORKS_ON (attribute Hours) | EMPLOYEE (M) and PROJECT (N) | M:N | double lines on both sides |
| SUPERVISION | EMPLOYEE as supervisor (1) and as supervisee (N) | 1:N | single lines |
| DEPENDENTS_OF (double diamond: identifying) | EMPLOYEE (1) and DEPENDENT (N) | 1:N | EMPLOYEE single, DEPENDENT double |
Steps 1 and 2: entity setsالكيانات
Steps 1 and 2: strong and weak entity sets
Create a relation R that includes all the simple attributes of E. EMPLOYEE (Fname, Minit, Lname, Ssn, Bdate, Address, Sex, Salary); DEPARTMENT (Dname, Dnumber); PROJECT (Pname, Pnumber, Plocation).
Create a relation R with all simple attributes of the weak entity set and include the primary key of the owner as foreign key attributes of R. DEPENDENT (Essn, name, Sex, Birthdate, Relationship) — Essn is highlighted as the owner's key.
- In the schemas on this screen, bold marks the attributes underlined on the slides (the primary key).
Step 3: 1:1 relationshipsعلاقات 1:1
Step 3: binary 1:1 relationship sets
- 1Foreign key approachالمفتاح الأجنبيInclude in S the primary key of T. **Better to choose an entity set with total participation in R in the role of S.**
- 2Merged relation optionالدمجMerge the two entity sets and the relationship into one relation — **appropriate when both participations are total**.
- 3Cross-reference optionعلاقة الربطA **third relation R** cross-referencing the primary keys of S and T.
MANAGES (slide 8)
- The primary key of EMPLOYEE goes into DEPARTMENT, renamed Mgr_ssn; the relationship attribute Start_date goes too, as Mgr_start_date.
- EMPLOYEE (Fname, Minit, Lname, Ssn, Bdate, Address, Sex, Salary) and DEPARTMENT (Dname, Dnumber, Mgr_ssn, Mgr_start_date, No.of_Emp), with an arrow from Mgr_ssn to Ssn.
1:1 example: manageمثال 1:1
Step 3: binary 1:1 relationship sets
المعطيات
- EMPLOYEE
- (EmpNo, Lname, Fname, DOB) — participation (0,1)
- BRANCH
- (BrnNo, Name) — participation (1,1)
- manage
- 1:1, attributes StartD, EndD
خطوات الحل
- Use the foreign key approach; the side with total participation (BRANCH) takes the role of S.
- Add EmpNo and the relationship attributes to BRANCH.
النتيجة
EMPLOYEE(EmpNo, Lname, Fname, DOB); BRANCH(BrnNo, Name, EmpNo, StartDate, EndDate)
Step 4: 1:N relationshipsعلاقات 1:N
Step 4: binary 1:N relationship sets
For each binary 1:N relationship set (slide 9)
- 1
Identify the relation S at the N-side of the relationship set.
- 2
Include the primary key of the other entity set as a foreign key in S.
- 3
Include the simple attributes of the 1:N relationship as attributes of S.
| Relationshipالعلاقة | Foreign key addedالمفتاح الأجنبي | Resultالنتيجة |
|---|---|---|
| WORKS_FOR | Dnumber of DEPARTMENT → EMPLOYEE.Dno | EMPLOYEE (…, Dno) |
| SUPERVISION | Ssn of EMPLOYEE → EMPLOYEE.Super_ssn (same relation) | EMPLOYEE (…, Dno, Super_ssn) |
| CONTROLS | Dnumber of DEPARTMENT → PROJECT.Dnum | PROJECT (Pname, Pnumber, Plocation, Dnum) |
Step 5: M:N relationshipsعلاقات M:N
Steps 5 and 6: M:N relationships and multivalued attributes
For each binary M:N relationship set: create a new relation S; include the primary keys of the participating entity sets as foreign keys in S; include any simple attributes of the relationship set.
Step 6: multivalued attributesمتعددة القيم
Steps 5 and 6: M:N relationships and multivalued attributes
For each multivalued attribute A: create a new relation R; its primary key is the combination of A and K (the key of the entity); if A is composite, include its simple components.
Step 7: n-ary relationshipsالعلاقات النونية
Step 7: n-ary relationship sets
For each n-ary relationship set R: create a new relation S to represent R; include the primary keys of the participating entity sets as foreign keys; include any simple attributes.
The COMPANY result and the ER–relational correspondenceالنتيجة والتقابل
Steps 5 and 6: M:N relationships and multivalued attributes
Result for COMPANY (slide 12)
- EMPLOYEE (Fname, Minit, Lname, Ssn, Bdate, Address, Sex, Salary, Dno, Super_ssn)
- DEPARTMENT (Dname, Dnumber, Mgr_ssn, Mgr_start_date, No.of_Emp)
- DEPT_LOCATIONS (Dnumber, Dlocation)
- PROJECT (Pname, Pnumber, Plocation, Dnum)
- WORKS_ON (Essn, Pno, Hours)
- DEPENDENT (Essn, name, Sex, Birthdate, Relationship)
- In the schemas on this screen, bold marks the attributes underlined on the slides (the primary key).
| ER modelنموذج ER | Relational modelالنموذج العلائقي |
|---|---|
| Entity set | "Entity" relation |
| 1:1 or 1:N relationship set | Foreign key |
| M:N relationship set | "Relationship" relation and two foreign keys |
| n-ary relationship set | "Relationship" relation and n foreign keys |
| Simple attribute | Attribute |
| Composite attribute | Set of simple component attributes |
| Multivalued attribute | Relation and foreign key |
Figure 7.2: the COMPANY relational schemaالشكل 7.2
Steps 5 and 6: M:N relationships and multivalued attributes
| Relation | Attributes | Arrows |
|---|---|---|
| EMPLOYEE | Fname, Minit, Lname, Ssn, Bdate, Address, Sex, Salary, Super_ssn, Dno |
|
| DEPARTMENT | Dname, Dnumber, Mgr_ssn, Mgr_start_date, No.of Emp (added in a highlighted box) | Mgr_ssn → EMPLOYEE.Ssn |
| DEPT_LOCATIONS | Dnumber, Dlocation | Dnumber → DEPARTMENT.Dnumber |
| PROJECT | Pname, Pnumber, Plocation, Dnum | Dnum → DEPARTMENT.Dnumber |
| WORKS_ON | Essn, Pno, Hours |
|
| DEPENDENT | Essn, Dependent_name, Sex, Bdate, Relationship | Essn → EMPLOYEE.Ssn |
Options 8A and 8Bالخياران 8A و8B
Step 8: mapping specialization or generalization
Option 8A — superclass and subclasses8A
- A relation for C with {k, a1, …, an}; a relation for each subclass Si with {k} ∪ attributes of Si; PK k.
- Works for any specialization (total or partial, disjoint or overlapping).
- EMPLOYEE(Ssn, Fname, Minit, Lname, Birth_date, address, Job_type); SECRETARY(Ssn, TypingSpeed); TECHNICIAN(Ssn, TGrade); ENGINEER(Ssn, EngType) — Ssn of each subclass in red (the foreign key).
Option 8B — subclass relations only8B
- A relation for each subclass with its attributes ∪ {k, a1, …, an}; PK k; no relation for C.
- Only works if the subclasses are total; only recommended if disjoint.
- CAR (Vehicle_id, License_plate_no, Price, Max_speed, No_of_passengers); TRUCK (Vehicle_id, License_plate_no, Price, No_of_axles, Tonnage).
| Slide | Superclass | Specialization | Subclasses |
|---|---|---|---|
| 23, 27 (option 8A) |
| on Job Type (circle, no letter) |
|
| 24, 28 (option 8B) | VEHICLE (VehicleId, Price, LicensePlateNo) | d (disjoint) |
|
- Slide 27 draws the 8A result as tables: EMPLOYEE (Ssn, Fname, Minit, Lname, Birth_date, Address, Job_type); SECRETARY (Ssn, Typing_speed); TECHNICIAN (Ssn, Tgrade); ENGINEER (Ssn, Eng_type) — an arrow from each subclass Ssn to EMPLOYEE.Ssn.
- Slide 28 draws CAR and TRUCK as tables with the attributes above.
Options 8C and 8Dالخياران 8C و8D
Step 8: mapping specialization or generalization
Option 8C — one type attribute8C
- A single relation with all attributes of C and of every subclass ∪ {t}; t is a type (discriminating) attribute naming the subclass of each tuple.
- Works only for disjoint subclasses.
- EMPLOYEE (Ssn, Fname, Minit, Lname, Birth_date, Address, Job_type, Typing_speed, Tgrade, Eng_type) — Job_type circled on the slide.
Option 8D — multiple type attributes8D
- A single relation with all attributes ∪ {t1, …, tm}; each ti is a Boolean showing whether the tuple belongs to Si.
- Used for overlapping subclasses.
- PART (Part_no, Description, Mflag, Drawing_no, Manufacture_date, Batch_no, Pflag, Supplier_name, List_price) — Mflag and Pflag are the Boolean type fields, circled on the slide.
| Slide | Superclass | Specialization | Subclasses |
|---|---|---|---|
| 30 (option 8C) | EMPLOYEE (as on slide 23) | d (disjoint) on Job Type |
|
| 31 (option 8D) | PART (PartNo, Description) | o (overlapping) |
|
الخلاصة
أنهيت الدرس
الخطوة التالية: ثبّت المعلومات بالبطاقات، ثم اختبر نفسك بالأسئلة.
ما راجعته في هذا الدرس
- The seven-step ER-to-relational algorithmخوارزمية الخطوات السبع
- Steps 1 and 2: strong and weak entity setsالخطوتان 1 و2: الكيانات القوية والضعيفة
- Step 3: binary 1:1 relationship setsالخطوة 3: علاقات 1:1
- Step 4: binary 1:N relationship setsالخطوة 4: علاقات 1:N
- Steps 5 and 6: M:N relationships and multivalued attributesالخطوتان 5 و6: علاقات M:N والصفات متعددة القيم
- Step 7: n-ary relationship setsالخطوة 7: العلاقات النونية
- Steps 5 and 6: M:N relationships and multivalued attributesالخطوتان 5 و6: علاقات M:N والصفات متعددة القيم
- Step 8: mapping specialization or generalizationالخطوة 8: تحويل التخصيص أو التعميم