Transforming an ER Model into a Relational Schema  Cs263 Lecture 10.

Slides:



Advertisements
Similar presentations
Relational Database Design : ER- Mapping
Advertisements

Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Relational Database Design Via ER Modelling
Basic notation for supertype/subtype relationships
Enhanced Entity-Relationship Modeling. Strong and Weak Entity Types Strong entity: Each object is uniquely identifiable using primary key of that entity.
1 © Prentice Hall, 2002 Chapter 4: The Enhanced E-R Model and Business Rules Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B. Prescott,
1 Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – EER Model –21th June.
CHAPTER 3: THE ENHANCED E-R MODEL © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer,
© 2005 by Prentice Hall 1 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B.
ER-to-Relational Mapping Jan. 2012ACS-3902 Yangjun Chen1 ER-to-Relational Mapping Principles Specialization/Generalization -Superclass/Subclass Relationship.
Information Resources Management February 13, 2001.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Enhanced Entity-Relationship Modeling
Mapping from E-R Model to Relational Model Yong Choi School of Business CSUB.
ENTITY RELATIONSHIP DATA MODEL ELIZABETH GEORGE. INTRODUCTION Architect Aeronautical engineers Computer architects Traffic engineers.
The Enhanced E-R (EER) Model
Database Systems Chapter 7 ITM 354. Chapter Outline ER-to-Relational Schema Mapping Algorithm –Step 1: Mapping of Regular Entity Types –Step 2: Mapping.
Chapter Five Data Modeling with the Entity-Relationship Model.
CSCI 6442 Entity-Relation Data Modeling Copyright 2012, David C. Roberts, all rights reserved.
December 4, 2002 Data Modeling – James Cohen Enhanced Entity Relationship (EER) Model Presented by James Cohen.
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Chapter 3: The Enhanced E-R Model
Transforming ER & EER diagrams into Relations (Chapter 9)
© 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 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.
ER- and EER-to-Relational Mapping
Chapter 3 Relational Model Chapter 4 in Textbook.
Lecture4: Informal guidelines for good relational design Mapping ERD to Relation Ref. Chapter3 Lecture4 1.
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
Mapping from Data Model (ERD) to Relational Model
Switch off your Mobiles Phones or Change Profile to Silent Mode.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj ER Model Lecture 4 Mapping an ER model to tables © Akhilesh Bajaj,
IS 230Lecture 4Slide 1 Entity Relationship to Relational Model Mapping Lecture 5.
CS 370 Database Systems Lecture 9 The Relational model.
3 & 4 1 Chapters 3 and 4 Drawing ERDs October 16, 2006 Week 3.
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.
1 The Enhanced Entity Relationship Diagrams (E-ERDs)
E-R to Relational - Basic
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational Mapping with Constraints &
1 CS 430 Database Theory Winter 2005 Lecture 15: How to Convert an ER Model to Relations.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
11-1 Copyright  Oracle Corporation, All rights reserved. What Are Constraints? Constraints enforce rules at the table level. Constraints prevent.
Software School of Hunan University Database Systems Design Part III : Mapping ER Diagram to Relational Schema.
ER/EER to Relational Data Model 1 Database Design.
Database Design – Lecture 6 Moving to a Logical Model.
DatabaseIM ISU1 Chapter 7 ER- and EER-to-Relational Mapping Fundamentals of Database Systems.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences The Relational.
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 4: The Enhanced E-R Model Modern Database Management 9 th Edition Jeffrey A. Hoffer,
DATA MODELING AND DATABASE DESIGN DATA MODELING AND DATABASE DESIGN Part 2.
Copyright © 2016 Pearson Education, Inc. Modern Database Management 12 th Edition Jeff Hoffer, Ramesh Venkataraman, Heikki Topi CHAPTER 3: THE ENHANCED.
Introduction to Database Systems
Lecture 4: Logical Database Design and the Relational Model 1.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
The Enhanced E-R Model and Business Rules
Chapter 4: The Enhanced E-R Model and Business Rules
Chapter 4: Logical Database Design and the Relational Model
Chapter 4: Part B Logical Database Design and the Relational Model
Chapter 5: Logical Database Design and the Relational Model
Entity-Relationship Model
ER- and EER-to-Relational
Generalization.
Session 2 Welcome: The seventh learning sequence
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Relational Database Design by ER- and EER-to-Relational Mapping
Presentation transcript:

Transforming an ER Model into a Relational Schema  Cs263 Lecture 10

Transforming an ER Model into a Relational Schema There are a series of steps that are recommended for converting an E/ER model into a relational schema. These steps are not hard and fast rules, but rather a series of pertinent suggestions that the database designer must use wisely.

E/ER to Relational Schema Conversion Steps Step 1  For each ‘strong’ entity in the E/ER model, create a base relation with a column for each simple attribute of that entity.  The key attribute for the entity becomes the primary key of the relation.

Example – Converting ‘Strong’ Entities Emp EmpNo Salary Comm Hire Date Name Job EmpNoNumber(4) NameVarchar2(10) JobVarchar2(9) SalNumber(7,2) CommNumber(7,2) HireDateDate Emp Primary Key

Example – Converting ‘Strong’ Entities Dept DeptNo Location Name DeptNoNumber(2) NameVarchar2(14) LocationVarchar2(13) Dept Primary Key

E/ER to Relational Schema Conversion Steps Step 2 For each ‘weak’ entity, create a relation consisting of all the simple attributes of that entity and also include columns for the primary keys of those entities on whose existence it is dependent.

Example – Converting ‘Weak’ Entities Loan LoanNoChar(8) PaymentNoNumber(4)Date AmountNumber(9,2) Payment Composite Primary Key Payment Date Amount Loan No Payment No Discriminator

E/ER to Relational Schema Conversion Steps Step 3 When two entities participate in a one-to- many (1-M) relationship, the relation representing the entity with the M (Many) cardinality must have a foreign key column representing this relationship.

Example – Converting (1-M) Relationships Dept D# Emp Works in Assigned E# EmpNoNumber(4) NameVarchar2(10) JobVarchar2(9) SalNumber(7,2) CommNumber(7,2) HireDateDate DeptNoNumber(2) Emp Foreign Key As an Employee ‘must’ work in a department, then the DeptNo column in the Emp relation (table) cannot be NULL!

Example – Converting (1-M) Relationships EmpNoNumber(4) NameVarchar2(10) JobVarchar2(9) SalNumber(7,2) CommNumber(7,2) HireDateDate DeptNoNumber(2) Emp Foreign Key As an Employee ‘may not’ work in a department, then the DeptNo column in the Emp relation (table) can be NULL! Dept D# Emp Works in Assigned E#

E/ER to Relational Schema Conversion Steps Step 4 When two entities participate in a (1-1) relationship, a foreign key column must be included in the relation that represents one of these entities.

Example – Converting (1-1) Relationships Emp E# ID Card Belongs to Has ID# EmpNoNumber(6) NameVarchar2(10) Address Varchar2(200 ) DOBDate IDNoChar(10) Emp Foreign Key IDNoChar(10) IssuedDate ExpiresDate EmpNoNumber(6) ID Card Foreign Key EITHER ONE IS ACCEPTABLE

E/ER to Relational Schema Conversion Steps Step 5 When two entities participate in a many-to- many (M-M) relationship, then a relation must be created consisting of foreign keys for the two relations that represent the participating entities.

Example – Converting (M-N) Relationships Person P# Car Driven by Drives C# PersonNoNumber(6) CarNoChar(7) Person-Car Foreign Key Person P# Car C# Person-Car P#,C#

E/ER to Relational Schema Conversion Steps Step 6 Where an entity has a multi-valued attribute, create a relation with a column as a foreign key to the relation that represents the entity and a column for the multi-valued attribute.

Language Example – Multi-valued Attributes Programmer EmpNo Language Name EmpNoNumber(2) NameVarchar2(14) Programmer Primary Key EmpNoNumber(2) LanguageVarchar2(20) Prog-Lang Composite Primary Key

E/ER to Relational Schema Conversion Steps Step 7 When more than two entities participate in a relationship, then a relation must be created consisting of foreign keys to those relations representing the entities participating in the relationship.

Example – Converting Ternary Relationships Match Match No Player Player No Offence Offence No Booking MatchNo Number(4) PlayerNo Number(6) OffenceNo Number(3) Time Date Booking Composite Primary Key

E/ER to Relational Schema Conversion Steps Step 8 – Option A For sub-typing, create separate relations for each subtype consisting of those attributes which are peculiar to the given subtype, and include a foreign key to the super-type, that will act as the sub-type’s primary key. Create a separate relation for the super- type!

Example – Converting Sub-types EmployeeN o Name Address Employee EMPLOYEE Employee No Name Address SECRETARY Typing Speed TECHNICIAN Grade ENGINEER Type EmployeeN o TypingSpee d Secretary EmployeeN o Grade Technician EmployeeN o Type Engineer

E/ER to Relational Schema Conversion Steps Step 8 – Option B For sub-typing, create separate relations for each subtype consisting of all the attributes of the super-type, and all those which are peculiar to the given subtype. The primary key of the super-type becomes the primary key of each sub-type. Do not create a relation for the super-type!

Example – Converting Sub-types VehicleNo LicenceNo Price NoOfSeats Car VEHICLE Vehicle No Licence No Price CAR No of Seats TRUCK No of Axles Tonnage Truck VehicleNo LicenceNo Price NoOfAxles Tonnage