Translation of EER model into relational model Jose M. Peña

Slides:



Advertisements
Similar presentations
Relational Database Design : ER- Mapping
Advertisements

Relational Database Design Via ER Modelling
Mapping ER to Relational Model
Database technology Lecture 4: Mapping of EER model to relations Jose M. Peña
1 Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – EER Model –21th June.
Mapping an ERD to a Relational Database To map an ERD to a relational database, five rules are defined to govern how tables are constructed. 1)Rule for.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 7- 1.
Review Database Application Development Access Database Development ER-diagram Forms Reports Queries.
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.
Chapter 7 Relational Database Design by ER- and EER-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Database Systems ER and EER to Relational Mapping Toqir Ahmad Rana Database Management Systems 1 Lecture 18.
Ch 6: ER to Relational Mapping
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to-Relational Mapping.
Dr. Dang Tran Khanh M.eng. Tran Minh Quang
ER- and EER-to-Relational Mapping
Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008
Relational Database Design by ER- and EER-to-Relational Mapping
1 E/R to relational mapping algorithm – overview Mapping algorithm step 1-7 Steen Jensen, autumn 2013.
METU Department of Computer Eng Ceng 302 Introduction to DBMS Relational Database Design by ER to Relational Mapping by Pinar Senkul resources: mostly.
Slide Chapter 7 Relational Database Design by ER- to-Relational Mapping.
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
1 CS 430 Database Theory Winter 2005 Lecture 15: How to Convert an ER Model to Relations.
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.
Software School of Hunan University Database Systems Design Part III : Mapping ER Diagram to Relational Schema.
Relational Database Design by ER- and EER-to-Relational Mapping The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe,
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,
ER-TO-RELATIONAL MODEL MAPPING CONTENT SOURCES: ELAMSARI AND NAVATHE, FUNDAMENTALS OF DATABASE MANAGEMENT SYSTEMS.
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.
ER- Relational Mapping (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Transforming ER models to relational schemas
Mapping ER Diagrams to Tables
Introduction to Database Systems
Lecture (8) 1. Relational Database Design by ER- and EERR- to-Relational Mapping 2.
Relational Database Design by ER- and EER-to-Relational Mapping
Chapter 7 Relational Database Design by ER- and EERR-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 Copyright © 2004 Pearson Education, Inc.
Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
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
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
Relational Database Design by ER-to-Relational Mapping
9/5/2018.
Mapping ER Diagrams to Tables
11/15/2018.
Chapter 8: Mapping a Conceptual Design into a Logical Design
Relational Database Design by ER- and EER-to-Relational Mapping
Database technology Lecture 4: Mapping of EER model to relations
Relational Database Design by ER- and EER-to-Relational Mapping
Relational Database Design by ER- and EER-to- Relational Mapping
Relational Database Design by ER- and EERR-to-Relational Mapping
4/11/2019.
Mapping an ERD to a Relational Database
Relational Database Design by ER- and EER-to-Relational Mapping
CS4222 Principles of Database System
7/19/2019.
Relational Database Design by ER-to-Relational Mapping
Presentation transcript:

Translation of EER model into relational model Jose M. Peña

Overview Real world Model QueriesAnswers Databases Physical database DBMS Processing of queries and updates Access to stored data

Translation ER/EER to Relational Migrate from mini world model to a model understandable to a DBMS

EER model for the COMPANY database

ER to Relations Step 1: Mapping Regular Entity Types For each strong entity type R, create a relation E that has the same simple attributes as R. Derived attributes are not stored. Composite attributes are not stored, their component ones are stored. Multivalued attributes are treated later.

PROJECT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, …) DEPARTMENT ( Number, Name) Composite attributes are not stored, their component ones are stored. ”Location”: multivalued attributes are treated later. ”Number_of_employee”: derived attribute are not stored.

ER to Relations Step 5: Mapping M:N Relationship Types For each binary M:N relationship, identify the relations S and T that correspond to the connected entity types. Create a new relation R and use the primary keys from S and T as foreign keys and primary keys in R. If there are attributes on the relation these are also added to R. On delete/update CASCADE ?! ST R MN PKSPKT PKSPKTRatt ST R PKSPKT Ratt

DEPARTMENT( Number, Name) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, …) PROJECT( Number, Name, Location) WorksOn( Hours) Ssn, Number,

ER to Relations Step 4: Mapping 1:N Relationship Types 1. For each binary 1:N relationship, identify the relation S that represents the entity type on the N-side of the relationship type, and relation T that represents the entity type on the 1-side of the relationship type. Include as a foreign key in S the primary key of T. If there are attributes on the relation these are also added to S. On delete/update CASCADE ?! ST R N1 PKSPKT Ratt PKT PKSPKTRatt T S

DEPARTMENT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, …) PROJECT ( Number, Name) WorksOn( Hours) Ssn, Number, SupervisorSSN,...)

ER to Relations Step 4: Mapping 1:N Relationship Types 1. For each binary 1:N relationship, identify the relation S that represents the entity type on the N-side of the relationship type, and relation T that represents the entity type on the 1-side of the relationship type. Include as a foreign key in S the primary key of T. If there are attributes on the relation these are also added to S. 2. Implement as M:N relationship (unlike M:N relationship, now PK is PK(S)). Convenient if few tuples are participate in the relationship. On delete/update CASCADE ?! PKSPKT PKSPKTRatt ST R ST R N1 PKSPKT Ratt

DEPARTMENT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, …) PROJECT ( Number, Name) WorksOn( Hours) Ssn, Number, SupervisorSSN,...) Supervision(Ssn,SupervisorSSN)

ER to Relations Step 3: Mapping 1:1 Relationship Types 1. Implement as 1:N relationship (prefer the entity type with total participation, if any, as the entity type to which the foreign key is added). Convenient if few tuples participate in the relationship.

PROJECT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, …) DEPARTMENT ( Number, Name, Manager)

ER to Relations Step 3: Mapping 1:1 Relationship Types 1. Implement as 1:N relationship (prefer the entity type with total participation, if any, as the entity type to which the foreign key is added). Convenient if few tuples participate in the relationship. 2. For each binary 1:1 relationship B, identify the relations S and T that correspond to the incoming entity types. Merge S and T into a single relation R. Set the primary key of S or T as the primary key of R. Do not forget the attributes of the relationship type. Indicated only when S and/or T with total participation. ST R 11 PKSPKT Ratt PKSPKTRatt S

ER to Relations Step 2: Mapping Weak Entity Types For each weak entity type W with owner entity type E, create a relation R that has the same simple attributes as W, also add (as a foreign key) the primary key attributes from the relation that corresponds to E. Primary key attributes in R are composed of the primary key attributes from E and the partial key from W. On delete/update CASCADE ?!

DEPARTMENT( Number, Name) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, …) PROJECT ( Number, Name) WorksOn( Hours) Ssn, Number, SupervisorSSN,...) DEPENDENT(Ssn,Name, Sex, Birth_date, …)

ER to Relations Step 2: Mapping Weak Entity Types For each weak entity type W with owner entity type E, create a relation R that has the same simple attributes as W, also add (as a foreign key) the primary key attributes from the relation that corresponds to E. Primary key attributes in R are composed of the primary key attributes from E and the partial key from W. What if the owner entity is also weak ? On delete/update CASCADE ?!

ER to Relations Step 7: Mapping N-ary Relationship Types For each N-ary relationship with N>2, create a new relation S that contains the primary keys from the incoming relations as foreign keys. Primary key of S are those keys that come from cardinality constraints ≠ 1. Do not forget the attributes of the relationship type. On delete/update CASCADE ?!

N-ary relationships Example. A person works as an engineer at one company and as a gym instructor at another company. EmployeeJobType Company works as NM K Employee(PN, …) JobType(JID, …) Company(CID, …) Works_as(PN,JID, CID)

ER to Relations Step 6: Mapping multivalued attributes For each multivalued attribute A in R, create a new relation P that contains one attribute for each attribute in A and the primary key K of R as a foreign key. The primary key of P is the combination of K and some suitable simple attributes of A. Person Name PN Address Street PostNum Person(PN, Name) Address(PN, PostNum, Street) On delete/update CASCADE ?!

ER to Relations Materializing the relationship:  M:N implies two joins  1:N implies one or two joins  1:1 implies zero, one or two joins  N-ary implies N joins.

DEPARTMENT( Number, Name) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, …) PROJECT( Number, Name, Location) WorksOn( Hours) Ssn, Number, SELECT E.Fname, P.Name, W.Hours FROM EMPLOYEE E, PROJECT P, WorksOn W WHERE W.SSN = E.SSN AND W.Number = P.Number

ER to Relations Materializing the relationship:  M:N implies two joins  1:N implies one or two joins  1:1 implies zero, one or two joins  N-ary implies N joins.

PROJECT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, …) DEPARTMENT ( Number, Name, Manager) SELECT E.Fname, D.Name FROM EMPLOYEE E, DEPARTMENT D WHERE D.Manager = E.Ssn;

EER to Relations Step 8: Mapping Specialization a) create relations for each class (super+sub) X(ID, A) Y(ID, B) Z(ID, C) X ZY IDA B C U U * Always works.

EER to Relations Step 8: Mapping Specialization b) subclass relations only Y(ID, A, B) Z(ID, A, C) X ZY IDA B C U U * Works only for total participation. * Overlapping implies duplication.

EER to Relations Step 8: Mapping Specialization c) single relation with one type attribute and all subclass attributes X(ID, A, Type, B, C) X ZY d IDA B C U U * Works only for disjoint subclasses. * May produce many NULLs if many subclass-specific attributes exist. No needed if specialization is attribute-defined.

EER to Relations Step 8: Mapping Specialization d) single relation with multiple type attributes and all subclass attributes X(ID, A, IsY, B, IsZ, C) X ZY IDA B C U U * Always works. * May produce many NULLs if many subclass-specific attributes exist.

EER to Relations Materializing the superclass/subclasses  Option a, inner/outer join.  Option b, outer join (against theory…).  Option c, done.  Option d, done. May be more space inefficient but more time efficient.

EER to Relations a) create relations for each class (super+sub) X(ID, A) Y(ID, B) Z(ID, C) X ZY IDA B C U U SELECT X.ID, X.A, Y.B FROM X LEFT JOIN Y ON X.ID = Y.ID;

EER to Relations b) subclass relations only Y(ID, A, B) Z(ID, A, C) X ZY IDA B C U U SELECT Y.ID, Z.ID, Y.A, Z.A,Y.B, Z.C FROM Y FULL OUTER JOIN Z ON Y.ID = Z.ID;

EER to Relations Step 9: Mapping of Union Types a) If the defining superclasses have different primary keys, introduce a surrogate key in the union relation and use it as a foreign key in the superclasses. CompanyID PersonID Y(CompanyID, B, XID) Z(PersonID, C, XID) X(XID, A) X ZY u A B C U

EER to Relations Step 9: Mapping of Union Types b) If the defining superclasses use the same primary key, no need for surrogate key. Y(PersonID, B) Z(PersonID, C) X(PersonID, A) PersonID X ZY u A B C U * No FKs in Y and Z, unless total participation (correct figure 7.7 in the book)

Example: LARM days PersonOrganization TeacherStudent ResponsibleExhibition PID PhoneNum Name OrgNr Address Street Town PostNum is-contact-for organizes o u shows U U U NM N1 11 UID Description