4 relational data model section 2

59 564 0
4 relational data model section 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Step 1: Regular Entity Step 1: Mapping of Regular (Strong) Entity Types  Each regular entity type E  Create one new relation S.  Simple attributes of E  Attributes of S.  Composite attributes of E  Include only their simple component attributes in S.  Choose one of the key attributes of E as the primary key for S.  The other key attributes of E??? (Homework)  The new relation is called an entity relation.  Each tuple represents an entity instance.  E.g.:  Regular entity types EMPLOYEE, DEPARTMENT, and PROJECT  relations EMPLOYEE, DEPARTMENT, and PROJECT.  Ssn, Dnumber, and Pnumber are the primary keys for the relations EMPLOYEE, DEPARTMENT, and PROJECT.  Knowledge that Dname of DEPARTMENT and Pname of PROJECT are secondary keys is kept for possible use later in the design

DATABASE SYSTEMS RELATIONAL DATA MODEL Spring 2014 Nguyen Ngoc Thien An Contents Overview of Relational Data Model ER- & EER-to-Relational Mapping Relational Algebra ER- & EER-to-Relational Mapping Reading Suggestion: [1] Chapter ER- & EER-to-Relational Mapping Step 1: Regular Entity Types Step 2: Weak Entity Types Step 3: Binary 1:1 Relationship Types Step 6: Multivalued Attributes Step 5: Binary M:N Relationship Types Step 4: Binary 1:N Relationship Types Step 7: N-ary Relationship Types Step 8: Specialization or Generalization Step 9: Union Types (Categories) Minit Fname SSN Number_of_employees N Lname Name Address WORKS_FOR Name Locations Sex EMPLOYEE Start_date Salary Number DEPARTMENT MANAGES Bdate CONTROLS Hours N SUPERVISION N N N WORKS_ON PROJECT Name DEPENDENTS_OF Number N DEPENDENT Relationship Name Sex Birth_date Location ERD of Company Database EMPLOYEE Fname Minit Lname SSN Bdate Address Sex Salary Super_SSN Dno DEPARTMENT Dname Dnumber Mgr_SSN Mgr_start_date DEPT_LOCATIONS Dnumber Dlocation PROJECT Pname Pnumber Plocation Dnum WORKS_ON Essn Pno Hours DEPENDENT Essn Dependent_name Sex Bdate Relationship Relational Schema of Company Database ER- & EER-to-Relational Mapping Step 1: Regular Entity Types Step 2: Weak Entity Types Step 3: Binary 1:1 Relationship Types Step 6: Multivalued Attributes Step 5: Binary M:N Relationship Types Step 4: Binary 1:N Relationship Types Step 7: N-ary Relationship Types Step 8: Specialization or Generalization Step 9: Union Types (Categories) Step 1: Regular Entity  Step 1: Mapping of Regular (Strong) Entity Types  Each regular entity type E  Create one new relation S Simple attributes of E  Attributes of S  Composite attributes of E  Include only their simple component attributes in S  Choose one of the key attributes of E as the primary key for S  The other key attributes of E??? (Homework!!!)   The new relation is called an entity relation   Each tuple represents an entity instance E.g.:    Regular entity types EMPLOYEE, DEPARTMENT, and PROJECT  relations EMPLOYEE, DEPARTMENT, and PROJECT Ssn, Dnumber, and Pnumber are the primary keys for the relations EMPLOYEE, DEPARTMENT, and PROJECT Knowledge that Dname of DEPARTMENT and Pname of PROJECT are secondary keys is kept for possible use later in the design Minit Fname SSN Number_of_employees N Lname Name Address WORKS_FOR Name Locations Sex EMPLOYEE Start_date Salary Number DEPARTMENT MANAGES Bdate CONTROLS Hours N SUPERVISION N N N WORKS_ON PROJECT Name DEPENDENTS_OF Number N DEPENDENT Relationship Name Sex Birth_date Location Step 1: Regular Entity EMPLOYEE Fname Minit Lname SSN Bdate Address Sex Salary Super_SSN Dno DEPARTMENT Dname Dnumber Mgr_SSN Mgr_start_date DEPT_LOCATIONS Dnumber Dlocation PROJECT Pname Pnumber Plocation Dnum WORKS_ON Essn Pno Hours DEPENDENT 10 Essn Dependent_name Sex Bdate Relationship Step 1: Regular Entity ER- & EER-to-Relational Mapping 45 Step 1: Regular Entity Types Step 2: Weak Entity Types Step 3: Binary 1:1 Relationship Types Step 6: Multivalued Attributes Step 5: Binary M:N Relationship Types Step 4: Binary 1:N Relationship Types Step 7: N-ary Relationship Types Step 8: Specialization or Generalization Step 9: Union Types (Categories) Step 8: Specialization/Generalization 46  Step 8: Mapping Specialization/Generalization  Conventions Superclass 𝐶 and its 𝑚 subclasses {𝑆1 , 𝑆2 , … , 𝑆𝑚 }  The attributes of 𝐶 are 𝑘, 𝑎1 , 𝑎2 , … , 𝑎𝑛  𝑘 is the primary key of 𝐶  𝐴𝑡𝑡𝑟𝑠(𝑅): the attributes of relation R  𝑃𝐾(𝑅): the primary key of R   Mapping by using one of the four following options: Option  Option  Option  Option  8A: Multiple Relations - Superclass and Subclasses 8B: Multiple Relations - Subclass Relations only 8C: Single Relation with One Type Attribute 8D: Single Relation with Multiple Type Attributes Step – Option 8A & 8B 47  Option 8A: Multiple Relations - Superclass & Subclasses  Create a relation 𝐿 for 𝐶:    𝑃𝐾 𝐿 = 𝑘 Create a relation 𝐿𝑖 for each subclass 𝑆𝑖 (1 ≤ 𝑖 ≤ 𝑚):   𝐴𝑡𝑡𝑟𝑠 𝐿 = 𝑘, 𝑎1 , 𝑎2 , … , 𝑎𝑛 𝐴𝑡𝑡𝑟𝑠 𝐿𝑖 = 𝑘 ∪ 𝑎𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒𝑠 𝑜𝑓 𝑆𝑖 𝑃𝐾 𝐿𝑖 = 𝑘 For any specialization (total / partial, disjoint / overlapping) Option 8B: Multiple Relations - Subclass Relations only  Create a relation 𝐿𝑖 for each subclass 𝑆𝑖 ≤ 𝑖 ≤ 𝑚 :     𝐴𝑡𝑡𝑟𝑠 𝐿𝑖 = 𝑎𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒𝑠 𝑜𝑓 𝑆𝑖 ∪ {𝑘, 𝑎1 , 𝑎2 , … , 𝑎𝑛 } 𝑃𝐾 𝐿𝑖 = 𝑘 For total specialization Disjointness is recommended (overlapping  duplicated) Example Option 8A 48 Example - Option 8B 49 Step – Option 8C & 8D 50  Option 8C: Single Relation with One Type Attribute  Create a relation 𝐿:      𝐴𝑡𝑡𝑟𝑠 𝐿 = 𝑘, 𝑎1 , 𝑎2 , … , 𝑎𝑛 ∪ {𝑎𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒𝑠 𝑜𝑓 𝑆1 } ∪ ⋯ ∪ 𝑎𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒𝑠 𝑜𝑓 𝑆𝑚 ∪ {𝑡} 𝑃𝐾(𝐿) = 𝑘 𝑡: a type (or discriminating) attribute indicating the subclass of each tuple For disjoint specialization  generate many NULL values if many specific attributes exist in the subclasses Option 8D: Single Relation with Multiple Type Attributes  Create a relation 𝐿:     𝐴𝑡𝑡𝑟𝑠 𝐿 = 𝑘, 𝑎1 , … , 𝑎𝑛 ∪ 𝑎𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒𝑠 𝑜𝑓 𝑆1 ∪ ⋯ ∪ 𝑎𝑡𝑡𝑟𝑖𝑏𝑢𝑡𝑒𝑠 𝑜𝑓 𝑆𝑚 ∪ 𝑡1 , … , 𝑡𝑚 𝑃𝐾(𝐿) = 𝑘 𝑡𝑖 (1 ≤ 𝑖 ≤ 𝑚): a Boolean type attribute indicating subclasses 𝑆𝑖 (s) of a tuple For overlapping specialization (but also for disjoint specialization) Example Option 8C 51 Example - Option 8D 52 Mapping Shared Subclasses (1) 53  Mapping of Shared Subclasses A shared subclass is a subclass of several classes indicating multiple inheritance These classes must all have the same key attribute  Can apply any of the options discussed in Step to a shared subclass, subject to the restriction discussed in Step of the mapping algorithm Mapping Shared Subclasses (2) 54 Mapping Shared Subclasses (3) 55 ER- & EER-to-Relational Mapping 56 Step 1: Regular Entity Types Step 2: Weak Entity Types Step 3: Binary 1:1 Relationship Types Step 6: Multivalued Attributes Step 5: Binary M:N Relationship Types Step 4: Binary 1:N Relationship Types Step 7: N-ary Relationship Types Step 8: Specialization or Generalization Step 9: Union Types (Categories) Step 9: Union Types 57  Step 9: Mapping of Union Types (Categories)    Create a new relation S for the category with a primary key Include any attributes of the category in S If superclasses have different keys:     Include a new key attribute, called surrogate key, as foreign key in each relation of the superclasses These foreign keys reference to the primary key of S E.g.: OWNER category If superclasses have the same key    No need for a surrogate key Primary keys of relations corresponding to superclasses reference to the primary key of S E.g.: REGISTERED_VEHICLE category 58 Q&A 59 [...]... rename it Mgr_start_date Step 3: Binary 1:1 Relationship (2) 17 PK1 E1 1 1 R E1(PK1,…,PK2, A) Step 3 – Case 1 PK1 E1 PK2 A E2(PK2,…) PK2 A 1 R E1(PK1,…,PK2,A) E1(PK1,…) E2 1 E2 E2(PK2,…) OR E2(PK2,…,PK1,A) Step 3: Binary 1:1 Relationship (3) 18  Case 2: Both entity types have optional participation in R Option 1: the same way in the case 1  Option 2:    Create a new relation S representing R  Include... Case 1 Step 4: Binary 1:N Relationship (3) 26 PK1 E1 PK2 A N 1 R E1(PK1,…,PK2,A) E2 E2(PK2,…) OR E1(PK1,…) E2(PK2,…) R(PK1,PK2,A) Step 4 – Case 2 Minit Fname SSN Number_of_employees N Lname Name Address 1 WORKS_FOR Name Locations Sex EMPLOYEE Start_date Salary 1 Number DEPARTMENT 1 MANAGES 1 Bdate CONTROLS Hours 1 N SUPERVISION N N N WORKS_ON PROJECT 1 Name DEPENDENTS_OF Number N DEPENDENT 27 Relationship... 2 E.g.: 1:N relationship types SUPERVISION, CONTROLS, WORKS_FOR:   WORKS_FOR, CONTROLS: include the primary key Dnumber of DEPARTMENT as foreign key in EMPLOYEE (called Dno) and in PROJECT (called Dnum) SUPERVISION: include the primary key of EMPLOYEE as foreign key in EMPLOYEE itself (called Super_ssn) Step 4: Binary 1:N Relationship (2) 25 PK1 E1 PK2 A N R E1(PK1,…,PK2,A) 1 E2 E2(PK2,…) Step 4. .. and E2 as foreign keys in S  One of them becomes the primary key of S The other is a unique key S  Include all the simple attributes and simple components of composite attributes of R in S The new relation is called a relationship relation  Each tuple in S represents an instance of R Step 3: Binary 1:1 Relationship (4) 19 PK1 PK2 A 1 E1 E1(PK1,…) R E2(PK2,…) 1 E2 R(PK1,PK2,A) OR E1(PK1,…) E2(PK2,…)... Pname Pnumber Plocation Dnum WORKS_ON Essn Pno Hours DEPENDENT 22 Essn Dependent_name Sex Bdate Relationship Step 3: Binary 1:1 Relationship ER- & EER-to -Relational Mapping 23 Step 1: Regular Entity Types Step 2: Weak Entity Types Step 3: Binary 1:1 Relationship Types Step 6: Multivalued Attributes Step 5: Binary M:N Relationship Types Step 4: Binary 1:N Relationship Types Step 7: N-ary Relationship Types... Generalization Step 9: Union Types (Categories) Step 4: Binary 1:N Relationship (1) 24  Step 4: Mapping of Binary 1:N Relationship Types  Case 1: The entity type E1 of N-side has total participation in R   Case 2: The entity type E1 of N-side has partial participation in R     The same way in the case 1 of the step 3 The same way in the case 2 of the step 3 Usually use the option 1 when E1 has...ER- & EER-to -Relational Mapping 11 Step 1: Regular Entity Types Step 2: Weak Entity Types Step 3: Binary 1:1 Relationship Types Step 6: Multivalued Attributes Step 5: Binary M:N Relationship Types Step 4: Binary 1:N Relationship Types Step 7: N-ary Relationship Types Step 8: Specialization or Generalization Step 9: Union Types (Categories) Step 2: Weak Entity 12  Step 2: Mapping of Weak Entity... OR E1(PK1,…) E2(PK2,…) R(PK1,PK2,A) Step 3 – Case 2 – Option 2 Step 3: Binary 1:1 Relationship (5) 20  Case 2: Both entity types have optional participation in R  Usage:   Option 1:  Drawback: May cause excessive NULL values in the foreign key  Usually used when the relation containing the foreign key has a high percentage of instances participating in R Option 2:  Drawback: Having an extra... Step 4: Binary 1:N Relationship EMPLOYEE Fname Minit Lname SSN Bdate Address Sex Salary Super_SSN Dno DEPARTMENT Dname Dnumber Mgr_SSN Mgr_start_date DEPT_LOCATIONS Dnumber Dlocation PROJECT Pname Pnumber Plocation Dnum WORKS_ON Essn Pno Hours DEPENDENT 28 Essn Dependent_name Sex Bdate Relationship Step 4: Binary 1:N Relationship ER- & EER-to -Relational Mapping 29 Step 1: Regular Entity Types Step 2: ... Location Step 2: Weak Entity EMPLOYEE Fname Minit Lname SSN Bdate Address Sex Salary Super_SSN Dno DEPARTMENT Dname Dnumber Mgr_SSN Mgr_start_date DEPT_LOCATIONS Dnumber Dlocation PROJECT Pname Pnumber Plocation Dnum WORKS_ON Essn Pno Hours DEPENDENT 14 Essn Dependent_name Sex Bdate Relationship Step 2: Weak Entity ER- & EER-to -Relational Mapping 15 Step 1: Regular Entity Types Step 2: Weak Entity

Ngày đăng: 16/08/2016, 19:53

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan