Translation ER/EER to relational

Similar documents
Outline. Note 1. CSIE30600 Database Systems ER/EER to Relational Mapping 2

Chapter 9: Relational DB Design byer/eer to Relational Mapping Relational Database Design Using ER-to- Relational Mapping Mapping EER Model

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

ER to Relational Mapping

Ch 9: Mapping EER to Relational. Follow a seven-step algorithm to convert the basic ER model constructs into relations steps 1-7

Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping

Relational DB Design by ER- and EER-to-Relational Mapping Design & Analysis of Database Systems

Database Management

This chapter discusses how to design a relational

ER-to-Relational Mapping

DATABASE DESIGN I - 1DL300

Relational Model. CS 377: Database Systems

Database design process

DATABASDESIGN FÖR INGENJÖRER F

Chapter 9 Outline. Relational Database Design by ER and EERto-Relational. Mapping Fundamentals of Database Systems

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences

MIT Database Management Systems Lesson 03: ER-to-Relational Mapping

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

DATABASE DESIGN I - 1DL300

DATABASTEKNIK - 1DL116

Mapping ER Diagrams to. Relations (Cont d) Mapping ER Diagrams to. Exercise. Relations. Mapping ER Diagrams to Relations (Cont d) Exercise

Topic 5: Mapping of EER Diagrams to Relations

Entity Relationship Data Model. Slides by: Shree Jaswal

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

RELATIONAL DATA MODEL

CSC 742 Database Management Systems

Database Systems ER Model. A.R. Hurson 323 CS Building

Information Systems Development 37C Lecture: Final notes. 30 th March 2017 Dr. Riitta Hekkala

Course Notes on From Entity-Relationship Schemas to Relational Schemas

Introduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

ECE 650 Systems Programming & Engineering. Spring 2018

LECTURE 6: GUIDELINES FOR GOOD RELATIONAL DESIGN MAPPING ERD TO RELATIONS

Lecture3: Data Modeling Using the Entity-Relationship Model.

Chapter (4) Enhanced Entity-Relationship and Object Modeling

Data Modeling with the Entity Relationship Model. CS157A Chris Pollett Sept. 7, 2005.

CS 405G: Introduction to Database Systems

Chapter 17. Methodology Logical Database Design for the Relational Model

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

Class Information. Textbooks. Grading. Final Project. Grading. CS 440: Database Management Systems. Instructor:

COSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1)

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

UNIVERSITY OF TORONTO MIDTERM TEST SUMMER 2017 CSC343H Introduction to Databases Instructor Tamanna Chhabra Duration 120 min No aids allowed

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 8 Data Modeling Advanced Concepts

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

SVY2001: Databases for GIS

KINGDOM OF SAUDI ARABIA-JAZAN UNIVERSITY COLLEGE OF COMPUTER SCIENCE & INFORMATION SYSTEMS 221 INFS 3 DATABASE SYSTEMS-1 REVIEW QUESTIONS

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

Database Technology. Topic 4: Enhanced Entity- Relationship (EER) Modeling

Overview Relational data model

SQL STRUCTURED QUERY LANGUAGE

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

LECTURE 3: ENTITY-RELATIONSHIP MODELING

CMP-3440 Database Systems

Relational Model and Relational Algebra. Slides by: Ms. Shree Jaswal

ECE 650 Systems Programming & Engineering. Spring 2018

Chapter 6: Entity-Relationship Model

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Lecture4: Guidelines for good relational design Mapping ERD to Relation. Ref. Chapter3

Using High-Level Conceptual Data Models for Database Design A Sample Database Application Entity Types, Entity Sets, Attributes, and Keys

1/24/2012. Chapter 7 Outline. Chapter 7 Outline (cont d.) CS 440: Database Management Systems

Chapter 8: Relational Algebra

Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

A taxonomy of SQL queries Learning Plan

COSC Assignment 2

EECS 647: Introduction to Database Systems

Query Processing & Optimization. CS 377: Database Systems

Slides by: Ms. Shree Jaswal

Relational Database Systems Part 01. Karine Reis Ferreira

Database Design Process

CS 348 Introduction to Database Management Assignment 2

E-R Diagram. Bagian I Entity Concept

High Level Database Models

DATABASE DESIGN I - 1DL300

Data Modeling Using the Entity-Relationship Model

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Sarajane Marques Peres, Ph.D. University of São Paulo Based on Elsmari, Navathe / Silberschatz, Korth, Sudarshan s books

Relational Databases Overview

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

DATABASE TECHNOLOGY. Spring An introduction to database systems

High-Level Database Models (ii)

COSC 304 Introduction to Database Systems. Entity-Relationship Modeling

Relational Model: History

From ER to Relational Model. Book Chapter 3 (part 2 )

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)

Chapter 3. Algorithms for Query Processing and Optimization

Database Applications (15-415)

SQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

Chapter Outline. Note 1. Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

Data Modeling Using the Entity-Relationship (ER) Model

THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)

OBJECTIVES. How to derive a set of relations from a conceptual data model. How to validate these relations using the technique of normalization.

DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL. 1 Powered by POeT Solvers Limited

L12: ER modeling 5. CS3200 Database design (sp18 s2) 2/22/2018

Fundamentals, Design, and Implementation, 9/e Copyright 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e by David M.

CMP-3440 Database Systems

Relational Model (cont d) & Entity Relational Model. Lecture 2

Objectives of logical design... Transforming the ERD diagram into relations. Relational database components. Mapping a composite attribute

Introduction to Data Management. Lecture #6 E-Rà Relational Mapping (Cont.)

DEPARTMENT DNAME DNUMBER MGRNAME MGRSTARTDATE

Transcription:

Database technology Lecture 4: Mapping of EER model to relations Jose M. Peña jose.m.pena@liu.se Translation ER/EER to relational Migrate from mini world model to a model understandable by a DBMS. 1

EER model for the COMPANY database 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. 2

PROJECT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, ) Composite attributes are not stored, their component ones are stored. DEPARTMENT ( Number, Name) Number_of_employee : derived attribute are not stored. Location : multivalued attributes are treated later. S PKS M Ratt N T PKT 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?! S PKS T PKT R PKS PKT Ratt 3

DEPARTMENT( Number, Name) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, ) PROJECT( Number, Name, Location) WorksOn( Ssn, Number, Hours) S PKS N 1 Ratt T PKT 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?! T PKT S PKS PKT Ratt 4

DEPARTMENT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, SupervisorSSN,...) ) PROJECT ( Number, Name) WorksOn( Ssn, Number, Hours) S PKS N 1 Ratt T PKT 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 the 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 a M:N relationship (unlike M:N relationship, now PK(R) is PK(S)). Convenient if few tuples participate in the relationship. On delete/update CASCADE?! S PKS T PKT R PKS PKT Ratt 5

DEPARTMENT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, SupervisorSSN,...) ) PROJECT ( Number, Name) WorksOn( Ssn, Number, Hours) Supervision( Ssn, SupervisorSSN) Step 3: Mapping 1:1 relationship types 1. Implement as a 1:N relationship (prefer the entity type with total participation, if any, as the entity type to which the foreign key is added). 6

PROJECT( Number, Name, Location) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, ) DEPARTMENT ( Number, Name, Manager) Step 3: Mapping 1:1 relationship types 1. Implement as a 1:N relationship (prefer the entity type with total participation, if any, as the entity type to which the foreign key is added). 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. S PKS 1 1 Ratt T PKT S PKS PKT Ratt 7

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. The 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, SupervisorSSN,...) ) PROJECT ( Number, Name) WorksOn( Ssn, Number, Hours) DEPENDENT( Ssn, Name, Sex, Birth_date, ) 8

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. The 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?! Example. A person works as an engineer at one company and as a gym instructor at another company. Employee N M works as JobType Employee(PN, ) K Company JobType(JID, ) Company(CID, ) Works_as(PN,JID, CID) 9

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. PostNum On delete/update CASCADE?! PN Address Street Person(PN, Name) Name Person Address(PN, PostNum, Street) 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. 10

DEPARTMENT( Number, Name) EMPLOYEE(Ssn, Bdate, Fname, Minit, Lname, ) PROJECT( Number, Name, Location) WorksOn( Ssn, Number, Hours) SELECT E.Fname, P.Name, W.Hours FROM EMPLOYEE E, PROJECT P, WorksOn W WHERE W.SSN = E.SSN AND W.Number = P.Number 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; 11

E Step 8: Mapping specialization a) Create relations for each class (super+subclass). ID X A X(ID, A) Y(ID, B) B Y Z C Z(ID, C) * Always works. E Step 8: Mapping specialization b) Create relations for the subclasses only. ID A X Y(ID, A, B) Y Z Z(ID, A, C) B C * Works only for total participation. * Overlapping implies duplication. 12

E Step 8: Mapping specialization c) Create a single relation with one type attribute and all subclass attributes. ID A X d X(ID, A, Type, B, C) B Y Z C * Works only for disjoint subclasses. * May produce many NULLs if many subclass-specific attributes exist. E Step 8: Mapping specialization d) Create a single relation with multiple type attributes and all subclass attributes. ID A X X(ID, A, IsY, B, IsZ, C) B Y Z C * Always works. * May produce many NULLs if many subclass-specific attributes exist. 13

E 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. E a) Create relations for each class (super+subclass). ID X A X(ID, A) Y(ID, B) B Y Z C Z(ID, C) SELECT X.ID, X.A, Y.B FROM X LEFT JOIN Y ON X.ID = Y.ID; 14

E b) Create relations for the subclasses only. ID A X Y(ID, A, B) Y Z Z(ID, A, C) B C SELECT Y.ID, Z.ID, Y.A, Z.A,Y.B, Z.C FROM Y FULL OUTER JOIN Z ON Y.ID = Z.ID; E 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. B CompanyID Y u U Z C PersonID Y(CompanyID, B, XID) Z(PersonID, C, XID) A X X(XID, A) 15

E Step 9: Mapping of union types b) If the defining superclasses use the same primary key, no need for surrogate key. B PersonID Y Z C PersonID Y(PersonID, B) A u U X Z(PersonID, C) X(PersonID, A) * No FKs in Y and Z, unless total participation (correct figure 7.7 in the book) Example: LARM days Town Name PID PhoneNum OrgNr Street Address PostNum Person o 1 1 is-contact-for Organization Teacher Student N 1 shows u U Responsible N organizes M Exhibition UID Description 16