CS4222 Principles of Database System

Slides:



Advertisements
Similar presentations
3/25/2017.
Advertisements

ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Relational Database Design Via ER Modelling
Mapping ER to Relational Model
1 Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – EER Model –21th June.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 7- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- and EER-to-Relational Mapping.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- Mapping.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to- Relational Mapping.
Database Systems Chapter 7 ITM 354. Chapter Outline ER-to-Relational Schema Mapping Algorithm –Step 1: Mapping of Regular Entity Types –Step 2: Mapping.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to- Relational Mapping.
Summary of Mapping constructs and constraints
Chapter 7 Relational Database Design by ER- and EER-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
December 4, 2002 Data Modeling – James Cohen Enhanced Entity Relationship (EER) Model Presented by James Cohen.
Database Systems ER and EER to Relational Mapping Toqir Ahmad Rana Database Management Systems 1 Lecture 18.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Chapter 91 ER & EER to Relational Mapping. Chapter 92 ER to Relational Mapping Step 1: For each regular entity type E in the ER schema, create a relation.
1 CSE 480: Database Systems Lecture 8: EER to Relational Mapping and DBDesigner Reference: Read Chapter 9 of the textbook.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to-Relational Mapping.
ER- and EER-to-Relational Mapping
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 7- 1.
Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008
Relational Database Design by ER- and EER-to-Relational Mapping
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 4 Normalization.
The Relational Model1 ER-to-Relational Mapping and Views.
METU Department of Computer Eng Ceng 302 Introduction to DBMS Relational Database Design by ER to Relational Mapping by Pinar Senkul resources: mostly.
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
Relational Database Design by ER- and EERR-to-Relational Mapping.
Chapter 6 Relational Database Design by ER- and EERR-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Relational Database Design by ER- and EER-to-Relational Mapping The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe,
Chapter 5 ER-to- Relational Mapping HUANG XUEHUA.
DatabaseIM ISU1 Chapter 7 ER- and EER-to-Relational Mapping Fundamentals of Database Systems.
ER/EER to Relational Mapping Chapter 9. STEP 1 ENTITY TYPE E (non weak) -> NEW RELATION T RELATION T: – includes all simple attributes (non composite,
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences The Relational.
ER-TO-RELATIONAL MODEL MAPPING CONTENT SOURCES: ELAMSARI AND NAVATHE, FUNDAMENTALS OF DATABASE MANAGEMENT SYSTEMS.
Relational Data Model and ER-/EER-to-Relational Mapping.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 9 Relational Database Design by ER- and EERR-to-Relational Mapping Slide 9- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 7- 1.
Relational Database Design by ER- and EER-to-Relational Mapping
Relational Database Design by ER- and EER-to-Relational Mapping
Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping.
Databases (CS507) CHAPTER 8
Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Lecture # 21 Chapter # 7 Relational Database Design by ER- and EER-to-Relational Mapping Muhammad Emran Database Systems.
Relational Database Design by ER- and ERR-to-Relational Mapping
Relational Database Design by ER- and EER-to- Relational Mapping
Relational Database Design by ER- and EER-to- Relational Mapping
EER Model – Chapter
Enhanced Entity-Relationship (EER) Modeling
Relational Database Design by ER- and EER-to-Relational Mapping
ER- and EER-to-Relational
Relational Database Design by ER- and EERR-to-Relational Mapping
9/5/2018.
11/15/2018.
CS4222 Principles of Database System
Chapter 8: Mapping a Conceptual Design into a Logical Design
Relational Database Design by ER- and EER-to-Relational Mapping
EER to Relational Mapping
ER-to-Relational Mapping Outline
Relational Database Design by ER- and EER-to-Relational Mapping
Relational Database Design by ER- and EER-to- Relational Mapping
CS4222 Principles of Database System
ER to Relational Mapping
Relational Database Design by ER- and EERR-to-Relational Mapping
4/11/2019.
Relational Database Design by ER- and EER-to-Relational Mapping
7/19/2019.
CS4222 Principles of Database System
Presentation transcript:

CS4222 Principles of Database System 6/16/2019 CS4222 Principles of Database System 9. ER/EER –to-Relational Mapping 2 Huiping Guo Department of Computer Science California State University, Los Angeles

Outline ER/EER -to-Relational Mapping 6/16/2019 Outline ER/EER -to-Relational Mapping Step 5: Map Relationship Sets with Participation Constraints Step 6: Mapping of Weak Entity Types Step 7: Mapping of Multivalued attributes Step 8: Mapping Specialization or Generalization Step 9: Mapping of Shared Subclasses (Multiple Inheritance) Step 10: Mapping of Union Types (Categories) 9. Mapping 2 CS4222_Su17

Step 5: Map Relationship Sets with Participation Constraints 6/16/2019 Step 5: Map Relationship Sets with Participation Constraints since name dname ssn sex dno budget 1 Manage Department Employees Each department has exactly one manager 9. Mapping 2 CS4222_Su17

Step 5: Map Relationship Sets with Participation Constraints Combine Manage and Department to one Relation CREATE TABLE Mg_Dept( ssn CHAR(11) NOT NULL, since DATE, dno INTEGER, dname Char(20), budget REAL, PRIMARY KEY (dno), FOREIGN KEY (ssn) REFERENCES Employees (ssn) ON DELETE RESTRICT ) 9. Mapping 2 CS4222_Su17

Step 6 Mapping of Weak Entity Types 6/16/2019 Step 6 Mapping of Weak Entity Types A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (1 owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. 9. Mapping 2 CS4222_Su17

Step 6 Mapping of Weak Entity Types 6/16/2019 Step 6 Mapping of Weak Entity Types For each weak entity type W in the ER schema with owner entity type E, create a relation R & include all simple attributes (or simple components of composite attributes) of W as attributes of R. Also, include as foreign key attributes of R the primary key attribute(s) of the relation(s) that correspond to the owner entity type(s). The primary key of R is the combination of the primary key(s) of the owner(s) and the partial key of the weak entity type W, if any. 9. Mapping 2 CS4222_Su17

Step 6 Mapping of Weak Entity Types Weak entity set and the identifying relationship set are translated into a single table. sex name birthdate dname Dependents Employees ssn Dependents_of 1 N 9. Mapping 2 CS4222_Su17

Step 6 Mapping of Weak Entity Types When the owner entity is deleted, all owned weak entities must also be deleted. CREATE TABLE Dependents_Of ( ssn CHAR(11) NOT NULL dname CHAR(20), birthdate Date, PRIMARY KEY (dname, ssn), FOREIGN KEY (ssn) REFERENCES Employees(ssn) ON DELETE CASCADE ) 9. Mapping 2 CS4222_Su17

Step 7: Mapping of Multivalued attributes 6/16/2019 Step 7: Mapping of Multivalued attributes For each multivalued attribute A, create a new relation R. This relation R will include an attribute corresponding to A, plus the primary key attribute K-as a foreign key in R-of the relation that represents the entity type of relationship type that has A as an attribute. The primary key of R is the combination of A and K. If the multivalued attribute is composite, we include its simple components. 9. Mapping 2 CS4222_Su17

Step 7: Mapping of Multivalued attributes Example: The relation DEPT_LOCATIONS is created. The attribute DLOCATION represents the multivalued attribute LOCATIONS of DEPARTMENT, while DNUMBER-as foreign key-represents the primary key of the DEPARTMENT relation. The primary key of R is the combination of {DNUMBER, DLOCATION}. 9. Mapping 2 CS4222_Su17

Step 8: Mapping Specialization or Generalization 6/16/2019 Step 8: Mapping Specialization or Generalization Convert each specialization with m subclasses {S1, S2,….,Sm} and generalized superclass C, where the attributes of C are {k,a1,…an} and k is the (primary) key, into relational schemas using one of the four following options: Option 8A: Multiple relations-Superclass and subclasses Option 8B: Multiple relations-Subclass relations only Option 8C: Single relation with one type attribute Option 8D: Single relation with multiple type attributes 9. Mapping 2 CS4222_Su17

Step 8: Mapping Specialization or Generalization 6/16/2019 Step 8: Mapping Specialization or Generalization Option 8A: Multiple relations-Superclass and subclasses Create a relation L for C with attributes Attrs(L) = {k,a1,…an} and PK(L) = k. Create a relation Li for each subclass Si, 1 < i < m, with the attributesAttrs(Li) = {k} U {attributes of Si} and PK(Li)=k. This option works for any specialization (total or partial, disjoint of over-lapping) 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 4.4 EER diagram notation for an attribute-defined specialization on JobType. 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 7.4 Options for mapping specialization or generalization. (a) Mapping the EER schema in Figure 4.4 using option 8A. 9. Mapping 2 CS4222_Su17

Step 8: Mapping Specialization or Generalization Option 8B: Multiple relations-Subclass relations only Create a relation Li for each subclass Si, 1 < i < m, with the attributes Attr(Li) = {attributes of Si} U {k,a1…,an} and PK(Li) = k. This option only works for a specialization whose subclasses are total (every entity in the superclass must belong to (at least) one of the subclasses). 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 4.3 Generalization. (b) Generalizing CAR and TRUCK into the superclass VEHICLE. 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 7.4 Options for mapping specialization or generalization. (b) Mapping the EER schema in Figure 4.3b using option 8B. Tonnage 9. Mapping 2 CS4222_Su17

Step 8: Mapping Specialization or Generalization Option 8C: Single relation with one type attribute Create a single relation L with attributes Attrs(L) = {k,a1,…an} U {attributes of S1} U…U {attributes of Sm} U {t} and PK(L) = k. The attribute t is called a type (or discriminating) attribute that indicates the subclass to which each tuple belongs Works for disjoint specialization 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 4.4 EER diagram notation for an attribute-defined specialization on JobType. 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 7.4 Options for mapping specialization or generalization. (c) Mapping the EER schema in Figure 4.4 using option 8C. Engtype 9. Mapping 2 CS4222_Su17

Step 8: Mapping Specialization or Generalization Option 8D: Single relation with multiple type attributes Create a single relation schema L with attributes Attrs(L) = {k,a1,…an} U {attributes of S1} U…U {attributes of Sm} U {t1, t2,…,tm} and PK(L) = k. Each ti, 1 < I < m, is a Boolean type attribute indicating whether a tuple belongs to the subclass Si. Works for overlapping subclasses 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 4.5 EER diagram notation for an overlapping (non-disjoint) specialization. 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 7.4 Options for mapping specialization or generalization. (d) Mapping Figure 4.5 using option 8D with Boolean type fields Mflag and Pflag. 9. Mapping 2 CS4222_Su17

Step 9: Mapping of Shared Subclasses (Multiple Inheritance) 6/16/2019 Step 9: Mapping of Shared Subclasses (Multiple Inheritance) A shared subclass, such as STUDENT_ASSISTANT, is a subclass of several classes, indicating multiple inheritance. These classes must all have the same key attribute We can apply any of the options discussed in Step 8 to a shared subclass, subject to the restriction discussed in Step 8 of the mapping algorithm. Example both 8C and 8D are used for the shared class STUDENT_ASSISTANT. 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 4.7 A specialization lattice with multiple inheritance for a UNIVERSITY database. 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 7.5 Mapping the EER specialization lattice in Figure 4.6 using multiple options. course 9. Mapping 2 CS4222_Su17

Step 10: Mapping of Union Types (Categories) For mapping a category whose defining superclass have different keys, it is customary to specify a new key attribute, called a surrogate key, when creating a relation to correspond to the category. In the example below we can create a relation OWNER to correspond to the OWNER category and include any attributes of the category in this relation. The primary key of the OWNER relation is the surrogate key, which we called OwnerId. 9. Mapping 2 CS4222_Su17

FIGURE 4.8 Two categories (union types): OWNER and REGISTERED_VEHICLE. 9. Mapping 2 CS4222_Su17

FIGURE 9. 7 Mapping the EER categories (union types) in Figure 4 FIGURE 9.7 Mapping the EER categories (union types) in Figure 4.8 to relations. 9. Mapping 2 CS4222_Su17

FIGURE 7.1 The ER conceptual schema diagram for the COMPANY database. 6/16/2019 FIGURE 7.1 The ER conceptual schema diagram for the COMPANY database. 9. Mapping 2 CS4222_Su17

6/16/2019 FIGURE 7.2 Result of mapping the COMPANY ER schema into a relational schema. 9. Mapping 2 CS4222_Su17

Exercise 1 Employees Reports_To supervisor subordinate 1 sex name ssn 9. Mapping 2 CS4222_Su17

Exercise 1 Only ONE table is needed! CREATE TABLE Employees( ssn CHAR(11), name CHAR(20), sex CHAR, ssn_super CHAR(11) NOT NULL, PRIMARY KEY (ssn) FOREIGN KEY (ssn_super) REFERENCES Employees(ssn) ON DELETE restricted ON UPDATE CASCADE) 9. Mapping 2 CS4222_Su17

Exercise 2 1 1 name pname age ssn lot Dependents Employees Purchaser 6/16/2019 Exercise 2 name Employees ssn lot pname age Dependents 1 Purchaser Beneficiary 1 policyid cost Policies 9. Mapping 2 CS4222_Su17 7

Exercise 2 policyid INTEGER, cost REAL, ssn CHAR(11) NOT NULL, 6/16/2019 Exercise 2 The cardinality constraints allow us to combine Purchaser with Policies and Beneficiary with Dependents. Participation constraints lead to NOT NULL constraints. CREATE TABLE Policies ( policyid INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (policyid). FOREIGN KEY (ssn) REFERENCES Employees (ssn), ON DELETE CASCADE ) 9. Mapping 2 CS4222_Su17 8

Exercise 2 pname CHAR(20), age INTEGER, policyid INTEGER, 6/16/2019 Exercise 2 CREATE TABLE Dependents ( pname CHAR(20), age INTEGER, policyid INTEGER, PRIMARY KEY (pname, policyid). FOREIGN KEY (policyid) REFERENCES Policies(policyid), ON DELETE CASCADE ) 9. Mapping 2 CS4222_Su17 8