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
Search
Read the Text Version
- 1 - 25
Pages: