Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore Lecture 4 - ER to Relational Mappings

Lecture 4 - ER to Relational Mappings

Published by loukwhay_38, 2016-12-02 23:38:26

Description: Lecture 4 - ER to Relational Mappings

Search

Read the Text Version

Course Syllabus (updated)Week Lecture Lab/Assignment/Project11-12 Nov 2010 Introduction to databases -18-19 Nov 2010 Relational database design and ER model Assignment 1 (ER model)25-26 Nov 2010 Normalization Assignment 2 (Normalization)2-3 Dec 2010 Normalization (cont) Lab 1 (software installation)9-10 Dec 2010 ER to relational mapping + DDL - Introduction to SQL 200816-17 Dec 2010 Relational Algebra Test 1+ Project 1 specification release + Assignment 3 (Relational Algebra)23-24 Dec 2010 Midterm Exam Week30-31 Dec 2010 - Project 1 presentation (30 Dec 2010)6-7 Jan 2011 Database Indexing Project 2 specification release13-14 Jan 2011 T-SQL Lab 2 (DDL & T-SQL) + Assignment 4 (DDL & T-SQL)20-21 Jan 2011 ER to SQL mapping Assignment 5 (ER to SQL mapping)27-28 Jan 2011 Stored Procedure Lab 3 (Stored Procedure)3-4 Feb 2011 CUBE and Windows Assignment 6 (CUBE, Views, Triggers)10-11 Feb 2011 Views and Triggers Test 217-18 Feb 2011 - -24-25 Feb 2011 Final Exam Week Project 2 presentation (26 Feb 2011)

ER to Relational Mapping 09/12/2010 2

Logical DB Design: ER to Relational (DDL)• (Regular) Entity set to tables 3

Relationship Sets to Tables• 1:1 between A-R-B – Foreign key approach • DEPT(dno, dname, …, eno) and MANAGER(eno, ename, …) • โดยปกติจะใชกับ entity type ท่ีเปน total participation ใน relationship – Merged relation approach • LOC-BRANCH(locID, branchID, …) • เหมาะสาํ หรบั กรณีท่ที ั้งสอง entities เปน แบบ total participations – Cross-reference or relationship relation approach • MANAGE(dno-eno) 4

Relationship Sets to Tables• 1:N between A-R-B – Foreign key approach • ใช primary key ของ 1-side entity type มาเปน foreign key ของ N- side entity type • DEPT(dno, dname, …) and EMP(eno, dno, ename, …) • นาํ attributes ของ relationship type มารวมเขาเปน attributes ของ N- side entity • DEPT(dno, dname, …) and EMP(eno, dno, ename, start_date, …) 5

Relationship Sets to Tables• N:M between A-R-B – Relationship relation approach • สรา งตารางขนึ้ มาใหมหนึ่งตารางสําหรับ relationship R • โดยให primary key ของตารางใหมนีเ้ ปน การรวมกนั ของ primary keys ของ A กบั B • และใหน ํา attributes ของ relationship type R มาเปน attibutes ของ ตารางใหมน้ี • PROJ(pno, proj_name, …) and EMP(eno, dno, ename, start_date, …) • WORKS_ON(pno, eno, location, start_date) 6

Mapping Relationships in DDL• แสดง foreign key constraint โดยใชคําสั่ง FOREIGN KEY – FK approach – Relationship relation approach 7

Preserving Total Participation Constraints• Basic Technique: – NOT NULL – ON DELETE [OPTION]• Advanced technique: – CHECK 8

Review: Weak Entities• Weak entity set สามารถจาํ แนกไดโดยการพิจารณา primary key ของ entity set อีกตัวหน่ึง ซึ่งคือ owner entity – Owner entity set กบั weak entity set ตอ งมคี วามสมั พันธแ บบ 1:N (1 owner, many weak entities) – และ weak entity set ตอ งอยใู นลักษณะของ total participation ในความสมั พันธน ี้ 9

Translating Weak Entity Sets• ขอ มลู ของ Weak entity set และ relationship set จะถูกรวมเขา ดว ยกนั ในหน่ึงตาราง – ในตารางน้ี primary key ของ owner entity จะถูกรวมเขา กบั partial key ของ weak entity เพอ่ื สรางเปน primary key ของตาราง – เราจําเปนตอ งรักษา total participation constraint ใน SQL mapping โดยใชคาํ สั่ง CASCADE 10

Review: ISA Hierarchy• ใน ISA Hierarchy น้ัน attributes จะถกู inherited• หมายความวา ถา A ISA B แลว ทุกๆ A entity จะถกู พจิ ารณาวาเปน B entity ดวย (Query answers should reflect this)• Overlapping constraints: • Joe สามารถเปนทงั้  Hourly_emps entity และ Contract_Emps entity ได หรือไม? (allowed/disallowed)• Covering constraints:  • ทกุ ๆ Employee entity  จําเปนตองเปน  Hourly_emps entity หรอื   Contract_Emps entity อยางใดอยา งหนงึ่ หรอื ไม? (yes/no) 11

Translating ISA Hierarchy to Relations • Option A: Multiple relations: superclass and subclasses – General approach: ใชไดกับ ISA Hierarchy ในทุกๆกรณี – Result: – Constraints: ถา หาก Employee tuple ที่ถูกอา งถึงถกู ลบ จาํ เปนตองลบ Hourly_Emps tuple ตามไปดวย – Queries ท่เี ก่ียวของกับ Employees น้ันงา ย แต queries ท่เี กีย่ วขอ งกบั Hourly_Emps เพียงอยางเดียวจาํ เปนตองทําการ join เพื่อใหไดคา ของ attributes บางตัว เชน eid, ename, lot 12

Translating ISA Hierarchy to Relations • Option B: Multiple relations – subclass relations only – ใชไดก็ตอ เมอ่ื covering constraint เปน yes – Result: – Queries ทเี่ ก่ยี วของกับ employees จาํ เปนตองมกี ารทํา union operations • Could be costly if overlapping 13

Translating ISA Hierarchy to Relations • Option C: Single relation with one type attribute – เหมาะสําหรบั กรณีที่ overlapping constraint เปน No ซึ่งคือ disjoint – Result:– แตจะทําใหมี NULL Values จาํ นวนมาก 14

Miscellaneous 15

Appendix• A – total participation• B – weak entities• C – is-a hierarchy• D – multi-valued attributes

A. Existence Dependence

B. Weak Entities

Weak Entities

Weak Entity vs Existence Constraint• In the existence constraint example, LoanNo can uniquely identify a Loan in the database so it is not a weak entity.• The existence constraint means that you cannot create a Loan record without first knowing who borrowed the loan

C. Limitations of ER model



D. Multi-valued Attributes

4NF – กําจดั MVD และเปน 4NF

4NF – กําจดั MVD และเปน 4NF


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook