Transforming ER & EER diagrams into Relations (Chapter 9)

Slides:



Advertisements
Similar presentations
Week 5 Relational Database Design by ER- -to-Relational Mapping.
Advertisements

Relational Database Design Via ER Modelling
ER Modeling Case Studies
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 7- 1.
Mapping from E-R Model to Relational Model Yong Choi School of Business CSUB.
Database Systems Chapter 7 ITM 354. Chapter Outline ER-to-Relational Schema Mapping Algorithm –Step 1: Mapping of Regular Entity Types –Step 2: Mapping.
Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – ER Model.
Chapter 7 Relational Database Design by ER- and EER-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Database Systems ER and EER to Relational Mapping Toqir Ahmad Rana Database Management Systems 1 Lecture 18.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 The Relational Model (Advanced)
 Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by 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
the Entity-Relationship Model
Chapter 5 1 © Prentice Hall, 2002 Chapter 5: Transforming EER Diagrams into Relations Mapping Regular Entities to Relations 1. Simple attributes: E-R attributes.
Converting ER model Into Relational Table
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 7 Relational Database Design by ER- to-Relational Mapping.
CS 370 Database Systems Lecture 9 The Relational model.
Initial Design of Entity Types for the COMPANY Database Schema Based on the requirements, we can identify four initial entity types in the COMPANY database:
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.
3 & 4 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Keys Consists of one or more attributes that determine other.
Database Management COP4540, SCS, FIU Database Modeling Using the Entity-Relationship Model (Continued)
Chapter 3 Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
Enhanced Entity-Relationship and Object Modeling Chapter 4
Relational Database Design by ER- and EERR-to-Relational Mapping.
Entity-Relationship Model Chapter 3 II COSC 457 Sungchul Hong.
Data Modeling Using the Entity-Relationship (ER) Data Model (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
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.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 3 Data Modeling Using Entity-Relationship Model.
Data Modeling Using the Entity-Relationship (ER) Data Model.
Chapter 3: Data Modeling Using the Entity-Relationship (ER) Data Model
ER-TO-RELATIONAL MODEL MAPPING CONTENT SOURCES: ELAMSARI AND NAVATHE, FUNDAMENTALS OF DATABASE MANAGEMENT SYSTEMS.
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 9 Relational Database Design by ER- and EERR-to-Relational Mapping Slide 9- 1.
Database Management COP4540, SCS, FIU Database Modeling Using the Entity- Relationship Model (Continued)
Introduction to Database Systems
Lecture (8) 1. Relational Database Design by ER- and EERR- to-Relational Mapping 2.
Lecture 4: Logical Database Design and the Relational Model 1.
Relational Database Design by ER- and EER-to-Relational Mapping
Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
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.
Logical Database Design and the Rational Model
Relational Database Design by ER- and ERR-to-Relational Mapping
Relational Database Design by ER- and EER-to- Relational Mapping
Chapter 4: Part B Logical Database Design and the Relational Model
Relational Database Design by ER- and EER-to-Relational Mapping
Relational Database Design by ER- and EERR-to-Relational Mapping
Relational Database Design by ER-to-Relational Mapping
9/5/2018.
11/15/2018.
Chapter 8: Mapping a Conceptual Design into a Logical Design
Relational Database Design by ER- and EER-to-Relational Mapping
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
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
7/19/2019.
Relational Database Design by ER-to-Relational Mapping
Presentation transcript:

Transforming ER & EER diagrams into Relations (Chapter 9) Database Management COP4540, SCS, FIU

Overview A relatively straightforward process with a well-defined set of rules. Many CASE Tools can automatically perform many of the conversion steps. CASE tools often cannot model complex data relationships. There are sometimes legitimate alternatives where you will need to choose a particular solution. You must be prepared to perform a quality check on the results obtained with a CASE Tool. Database Management COP4540, SCS, FIU

Map Simple Regular Entities Each regular entity type in an ER diagram is transformed into a relation. The name given to the relation is generally the same as the entity type. Each simple attribute of the entity type become an attribute of the relation. Choose one of the key(s) as primary key of the relation. How about composite attributes? How about multi-valued attributes? Database Management COP4540, SCS, FIU

Map Composite Attributes When a regular entity type has a composite attribute, only the simple component attributes of the composite attribute are included in the new relation. Street Name City Address ID COSTOMER State Zip CUSTOMER(ID, Name, Street, City, State, Zip) Database Management COP4540, SCS, FIU

Map Multi-valued Attributes When a regular entity type contains a multivalued attribute, two new relations (rather than one) are created. The first relation contains all of the attributes of the entity type except the multi-valued attribute. The second relation contains two sets of attributes. The primary key from the first relation, which becomes a foreign key of the second relation. Multi-valued attribute itself. The primary key of the second of relation is the combination of all attributes. The name of the second relation should capture the meaning of the multi-valued attribute. Database Management COP4540, SCS, FIU

Example EMPLOYEE SSN Skills Street Name City Address State Zip EMPLOYEE(SSN, Name, State, City, State, Zip) EMPLOYEE_SKILL(SSN, Skill) Database Management COP4540, SCS, FIU

Map Binary One-Many Relationship Create a relation for each of the two entity types participating in the relationship. Include the primary key attribute (or attributes) of the entity on the one-side of the relationship as a foreign key in the relation that is on the many-side of the relationship ( a mnemonic you can use to remember this rule is this: The primary key migrates to many side). DeptName SSN N 1 Major_in STUDENT DEPT Name STUDENT(SSN, Name, DeptName) DPET(DeptName) Database Management COP4540, SCS, FIU

Map Binary Many-Many Relationships Suppose that there is a binary relationship (M:N) between two entity types A and B. For such a relationship, create a new relation C: Include as foreign key attributes in C the primary key for each of the two participating entity type. These attributes become the primary key of C. Any attributes that are associated with the relationship are included with the relation C. Grade CID Name taking SID STUDENT COURSE Text N M STUDENT(SID, NAME) COURSE(CID, Text) Taking(SID, CID, Grade) Database Management COP4540, SCS, FIU

Map Binary One-One Relationship Binary 1:1 relationship can be viewed as a special case of 1:m relationship. The process of mapping such a relationship to relations requires to steps: first, two relations are created, one for each of the participating entity type. Second, the primary key of one of the relations is included as foreign key in the other relation. Name DeptName Manages 1 1 SSN EMPLOYEE DEPT EMPLOYEE(SSN, Name, DeptName) EMPLOYEE(SSN, Name) DEPT(DeptName) DEPT(DeptName, ManagerSSN) Database Management COP4540, SCS, FIU

Map Unary One-Many Relationship The entity type in the unary relationship is mapped to a relation using the procedure described before. Then a foreign key attribute is added within the same relation that references the primary key values. Note that the foreign key attribute name should reflect the role name on the one-side. A recursive foreign key is a foreign key in a relation that references the primary key values of that same relation. Name Supervisee N SSN EMPLOYEE Manages 1 Supervisor EMPLOYEE(SSN, Name, SupervisorSSN) Database Management COP4540, SCS, FIU

Map Unary Many-Many relationship With this type of relationship: Two relations are created: one to represent the entity type in the relationship and the other an associative relation to represent the M:N relationship itself. The primary key of the associative relation consists of two parts: both take their values from the primary key of the other relation. Any attribute of the relationship is included in the associative relation. ID Item M Quantity Name PART Contains N Components Unit_cost COMPONENT(ItemID, ComponentID, Quantity) Database Management COP4540, SCS, FIU PART(ID, Name, Unit_Cost)

Map Weak Entities Dependants Employees For each weak entity type, create a new relation and include all of the simple attributes (or simple components of composite attributes) as attributes of this relation. Then, include the primary key of the owner relation as a foreign key attribute in this relation. The primary key of the new relation is the combination of this primary key of the owner and the partial key of the weak entity type. name addr. name SSN DEPENDANT_ OF N Dependants 1 salary Employees sex relationship birthdate sex birthdate Database Management COP4540, SCS, FIU

Example Results Employee( SSN, name, addr, salary sex, birthdate) Dependants(name, birthdate, sex, relationship, empSSN) The relation for the weak entity not only has the attributes of itself, but also has the key attributes of the other entity sets. Do not construct a relation for a “double-diamond” relationship. Database Management COP4540, SCS, FIU

Map Ternary (n-ary) Relationship It is recommended that you convert the ternary (n-ary) relationship to a number of binary relationships, and then transform the diagram into relationships. SName Quantity ProjName SUPPLY SUPPLIER PROJECT PART PartNo SUPPLIER PROJECT PART SName ProjName PartNo Quantity SUPPLY SS SPJ SP 1 N Database Management COP4540, SCS, FIU

Example Result SUPPLIER(SName) PROJECT(ProjName) SUPPLY(SName, ProjName, PartID, Quantity) PART(PartID) Database Management COP4540, SCS, FIU

Map Supertype/Subtype Relationships The relational data model does not yet directly support/subtype relationships. There are various strategies that database designer can use to represent these relationships. In this lecture, we introduce the most commonly employed strategy. Database Management COP4540, SCS, FIU

Mapping Strategy Create a separate relation for the supertype and for each of its subtypes. Assign to the relation created for the supertype the attributes that are common to all memebers of the supertype, including the primary key. Assign to the relation for each subtype the primary key of the supertype, and this primary key is also a foreign key that references the primary key in relation representing the supertype. Assign to the relation for each subtype the attributes that are unique to that subtype. Database Management COP4540, SCS, FIU

Example Database Management COP4540, SCS, FIU Name Address SSN EMPLOYEE Date_hired d    HOURLY EMPLOYEE SALARED EMPLOYEE CONSULTANT Hourly_rate Stock_option Contract_No. Billing_rate Annual_salary EMPLOYEE( SSN, Name, Address, Date_hired) HOURLY_EMPLOYEE(SSN, Hourly_Rate) SALARIED_EMPLOYEE(SSN, Annual_salary, Stock_Option) CONSULTANT(SSN, Contract_No, Billing_rate) Database Management COP4540, SCS, FIU

Map Categories Problem Solution Multiple supertypes may have different primary keys. Solution The concept of surrogate key, a specified new key attribute for the subtype. Database Management COP4540, SCS, FIU

Example CName Name Address SSN PERSON COMPANY Total_Balance BName  U BName  ACCOUNT HOLDER M Has_Acct N BANK Database Management COP4540, SCS, FIU

Example Results COMPANY(CName, Address, OwnerID) PERSON(SSN, Name, OwnerID) ACCOUNTHOLDER(OwnerID) HASACCOUNT(OwnerID, BName, Total_Balance) BANK(BName) Database Management COP4540, SCS, FIU