1 CS 430 Database Theory Winter 2005 Lecture 15: How to Convert an ER Model to Relations.

Slides:



Advertisements
Similar presentations
EER to Relation Models Mapping
Advertisements

Week 5 Relational Database Design by ER- -to-Relational Mapping.
Relational Database Design Via ER Modelling
Mapping ER to Relational Model
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
Chapter 6 Methodology Logical Database Design for the Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 7- 1.
Methodology Logical Database Design for the Relational Model
RELATIONSHIP  THE WAY TABLES ARE RELATED  A TABLE MUST PARTICIPATE IN AT LEAST ONE RELATIONSHIP  IN A BINARY RELATIONSHIP TWO ENTITIES PARTICIPATE 
Mapping of N:M Relationships PERSON-ID TITLE PERSON-NAME DATE-OF-BIRTH PERSON-ID PROJECT-ID HOURS-SPENT PROJECT-ID END-DATE START-DATE E-R Diagram PERSON.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to- Relational Mapping.
ER- Relational Mapping (Based on Chapter 7 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 4)
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.
Mapping ERM to relational database
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.
ER- and EER-to-Relational Mapping
Converting ER model Into Relational Table
Conversion from ER diagram to relational model
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- to-Relational Mapping.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- 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.
CS 370 Database Systems Lecture 9 The Relational model.
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Slide Chapter 7 Relational Database Design by ER- to-Relational Mapping.
Relational Database Design by ER- and EERR-to-Relational Mapping.
Software School of Hunan University Database Systems Design Part III : Mapping ER Diagram to Relational Schema.
DatabaseIM ISU1 Chapter 7 ER- and EER-to-Relational Mapping Fundamentals of Database Systems.
Data Modeling Using the Entity-Relationship (ER) Data Model.
Week 7-8 DBMS ER-Relational Mapping. ER-Relational Mapping.
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.
Database Design Slide 1 Database Design Lecture 7 part 2 Mapping ERD to Tables.
ER- Relational Mapping (Based on Chapter 9 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Transforming ER models to relational schemas
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.
Methodology - Logical Database Design. 2 Step 2 Build and Validate Local Logical Data Model To build a local logical data model from a local conceptual.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER- to-Relational Mapping.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
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.
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
Chapter (9) ER and EER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual.
9/5/2018.
Chapter (9) ER and EER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual.
11/15/2018.
Chapter 8: Mapping a Conceptual Design into a Logical Design
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
Relational Database Design by ER- and EERR-to-Relational Mapping
4/11/2019.
Relational Database Design by ER- and EER-to-Relational Mapping
Chapter (7) ER-to-Relational Mapping, and other Relational Languages
7/19/2019.
Relational Database Design by ER-to-Relational Mapping
Presentation transcript:

1 CS 430 Database Theory Winter 2005 Lecture 15: How to Convert an ER Model to Relations

2 Issue We do Conceptual Modeling using ER Models Our databases are relational  Look a little like ER models but not exactly How to we convert an ER model to relations for an RDBMS Note: Typically the resulting relations are 3NF

3 ER Model ER Model has:  Entities, Relationships, Attributes Relationships may have attributes May have multi-valued and composite attributes To convert to Relation Tables:  Need Keys for Entities  Relationships need cardinalities, e.g. 1:1, 1:n, m:n Example ER Model:  Figure 7.1 from Text Book

4 Steps Convert Independent (Strong, Regular) Entities Convert Dependent (Weak) Entities Convert Binary Relations  1:1  1:n  m:n Convert N-Ary Relationships (N>2) Convert Multi-Valued Attributes

5 Convert Independent Entities Create a new Relation for the Entity Make all simple (non-multi-valued, non- composite) attributes of the Entity into attributes of the Relation  For single-valued composite attributes, use the underlying simple attributes Choose some Key attribute(s) to be the Primary Key

6 Result So Far SSNFnameMinitLNameSexAddressBDateSalary DNameDNumber PNamePNumberPLocation EMPLOYEE DEPARTMENT PROJECT

7 Convert Dependent Entities Create a new Relation for the Entity Make all simple attributes into attributes of the relation (same as for Independent Entities) Add the primary key attribute(s) of the owning entity as a foreign key for the weak entity  Convert entities in order: If one weak entity owns another, convert the owner first Add ON UPDATE and ON DELETE  The usual approach is CASCADE

8 Result So Far SSNFnameMinitLNameSexAddressBDateSalary DNameDNumber PNamePNumberPLocation EMPLOYEE DEPARTMENT PROJECT ESSNDependent_NameSexBDateRelationship DEPENDENT

9 Map 1:1 Relations Foreign Key approach:  Include the primary key of one relation as a foreign key in the other  Include attributes of the relationship with the foreign key Merged Relationship  Merge the two relations Cross Reference  Add a new table with the keys from both entities (see m:n for example of this)

10 Result So Far SSNFnameMinitLNameSexAddressBDateSalary PNamePNumberPLocation EMPLOYEE DEPARTMENT PROJECT ESSNDependent_NameSexBDateRelationship DEPENDENT DNameDNumberMgrSSNMgrStartDate

11 Map 1:n Relations Let R be the “1 side”, S the “n side”  Include R’s key as a foreign key in S  Include any attributes of the relation together with the foreign key in S Or use the Cross Reference table approach (m:n approach)

12 Result So Far EMPLOYEE DEPARTMENT PROJECT ESSNDependent_NameSexBDateRelationship DEPENDENT DNameDNumberMgrSSNMgrStartDate PNamePNumberPLocationDNum SSNFnameMinitLNameSexAddressBDateSalarySuperSSNDNo

13 Map m:n Relations Create a new Relation to represent the Relationship Include the keys of the related entities as foreign keys in the relation Make the key of the relation the combined keys of the participating entities Include any simple attributes of the relationship as attributes of the relation Include CASCADE for UPDATE and DELETE (typical)

14 Result So Far EMPLOYEE DEPARTMENT PROJECT ESSNDependent_NameSexBDateRelationship DEPENDENT DNameDNumberMgrSSNMgrStartDate PNamePNumberPLocationDNum SSNFnameMinitLNameSexAddressBDateSalarySuperSSNDNo ESSNPNoHours WORKS_ON

15 Map N-Ary Relationships Treat the same as mapping m:n relationships  Create a new relation  Make the keys of all the parents, foreign keys of the relation  Make the key the combined foreign keys  Copy any simple attributes of the relationship as attributes of the relation

16 Map Multi-Valued Attributes Create a new Relation to represent the Attribute Include the key of the parent Relation as a foreign key for the new relation Include the Multi-Valued Attribute as an attribute of the relation Make the primary key the combination of the parent key and the attribute CASCADE on UPDATE and DELETE Note: If you have a composite multi-valued attribute, check to make sure you don’t have a weak entity  Impacts the set of attributes that make up the primary key

17 Final Result SSNFnameMinitLNameSexAddressBDateSalarySuperSSNDNo DNameDNumberMgrSSNMgrStartDate PNamePNumberPLocationDNum DNumberDLocation ESSNPNoHours ESSNDependent_NameSexBDateRelationship EMPLOYEE DEPT_LOCATIONS DEPARTMENT DEPENDENT WORKS_ON PROJECT