Mapping the ER Model to Relations(1)1 Overview  Mapping entity types  Mapping relationship types  One-to-one  One-to-many  Many-to-many.

Slides:



Advertisements
Similar presentations
Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Advertisements

Relational Database Design Via ER Modelling
--The Entity Relationship Model(3)--1 Outline  ER model  Overview  Entity types Attributes, keys  Relationship types  Weak entity types  Uses Crows.
Text-Book Chapters (7 and 8) Entity-Relationship Model
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Database Management Systems I Alex Coman, Winter 2006 Entity-Relationship.
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.
--The Entity Relationship Model(2)--1 Reflexive Rela1tionships  An entity may be related to another entity of the same type.  Example: A Customer could.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Introduction to Database Review 2. Crows-Feet Notation for ER Diagrams  This is an alternative to the diamond representation of relationships.  Diamond.
--The Entity Relationship Model(4)--1 Outline  ER model  Overview  Entity types Attributes, keys  Relationship types  Weak entity types  uses Integration.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to- Relational Mapping.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to- Relational Mapping.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
Chapter 7 Relational Database Design by ER- and EER-to-Relational Mapping Copyright © 2004 Pearson Education, Inc.
Ch 6: ER to Relational Mapping
 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.
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
DeSiamorewww.desiamore.com/ifm1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 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
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 7 Database Design and The E–R Model. 2 Goals n Facilitate DB design and represent the overall logical structure of the DB. n Definition Entities.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
1 Session 2 Welcome: The seventh learning sequence “ Reduction of an EER schema to tables“ Recap : In the previous learning sequence, we discussed the.
Entity-Relationship Model Using High-Level Conceptual Data Models for Database Design Entity Types, Sets, Attributes and Keys Relationship Types, Sets,
CS 370 Database Systems Lecture 9 The Relational model.
DeSiamorePowered by DeSiaMore1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
Msigwaemhttp//:msigwaem.ueuo.com/1 Database Management Systems (DBMS)  B. Computer Science and BSc IT Year 1.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Chapter 2 : Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of.
3 & 4 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel Keys Consists of one or more attributes that determine other.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Entity Relationship Diagram (2)
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.
ITTelkom Entity Relationship Diagram (1) CS2343 Perancangan Basisdata Relasional.
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.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
CS263 Lecture 5: Logical Database Design Can express the structure of a relation by a Tuple, a shorthand notation Name of the relation is followed (in.
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.
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,
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
1 © Prentice Hall, 2002 ITD1312 Database Principles Chapter 4B: Logical Design for Relational Systems -- Transforming ER Diagrams into Relations Modern.
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
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts - 6 th Edition Chapter 7: Entity-Relationship Model.
Introduction to Database Systems
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
Relational Database Design by ER- and EER-to-Relational Mapping
Relational Database Design by ER- and EER-to- Relational Mapping
Entity-Relationship Model
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
INF385T: Information Modeling — Class 11 Relational Database Design from ER Models Presented November 2 Karen Wickett,
Relational Database Design by ER- and EER-to-Relational Mapping
Session 2 Welcome: The seventh learning sequence
Relational Database Design by ER- and EER-to-Relational Mapping
Presentation transcript:

Mapping the ER Model to Relations(1)1 Overview  Mapping entity types  Mapping relationship types  One-to-one  One-to-many  Many-to-many

Mapping the ER Model to Relations(1)2 Mapping an EER Schema to Relations  In a sequence of steps, a set of relations is created.  Sometimes automated in CASE tools 1.Regular entity types 2.Weak entity types 3.Binary 1:1 relationship types 4.Binary 1:N relationship types 5.Binary M:N relationship types 6.n-ary relationship types 7.Multi-valued attributes

3 Customer Rents VideoTape Status Film Copies Performer StarsIn Children Reserves Store TapeNum NumCheckOuts AmountPaid ReturnDate Length Title Address Street City State CustomerIDTotalRes Name Location Role Name FilmID RentalPrice Distributor Kind Date Director parent (0,n) child (0,2) (0,m)(0,n) (1,1) (0,n) (0,m) (0,q) O Employee Preferred Customer Super- vises Supervisee (1,1) Manager (0,5) d Foreign Film Educational Film Music Video Spoken Language Subtitle Language Recommended Age “F”“M”“E” Kind Final Example EER Schema

Mapping the ER Model to Relations(1)4 1. Entity Type Maps to a Table  Create a table for each regular entity type.  One column in table for each simple attribute  Derived attributes may or may not appear (your choice)  Table’s primary key is the primary key of the entity type  Optimization: If there are no attributes other than the primary key, and if the entity participates totally in a relationship, then the table can be eliminated.

Mapping the ER Model to Relations(1)5 1. Entity Type Example  Consider the Film entity type  Maps to the following table (relational schema). Film (FilmID, Title, PubDate, RentalPrice, Distributor, Kind)  Note, primary key of table is key of entity type. Film TitleFilmID RentalPrice Distributor Kind Date Director

Mapping the ER Model to Relations(1)6 1. Entity Type Optimization Example  Assume each book is the basis for a film.  Book table can be eliminated by putting Book information into Film table since Book participates totally and has only key attributes.  Maps to the following table (relational schema). Film (FilmID, Title, BookTitle, Author, Publisher) Film TitleFilmID Book BookTitle Author Based On

Mapping the ER Model to Relations(1)7 2. Weak Entity Type Maps to a Table  Create a table for each weak entity type  One column for each simple attribute  Include column(s) for the primary key of each owner entity type. These columns are foreign keys  The primary key is the combination of each owner primary key and the partial key.

Mapping the ER Model to Relations(1)8 2. Weak Entity Type Example  Example:  VideoTape weak entity type (and Copies) maps to VideoTape (FilmID, TapeNum, Status)  Chose not to store derived attribute NumCheckOuts  Film entity type maps to different table  Copies relationship type is not mapped to a table VideoTape Status Film Copies TapeNum NumCheckOuts FilmID (1,1)(0,n)

Mapping the ER Model to Relations(1)9 Overview  Mapping entity types  Mapping relationship types  One-to-one  One-to-many  Many-to-many

Mapping the ER Model to Relations(1)10 Mapping Relationship Types - General  Each relationship type is mapped to a table  Columns are  Attributes of relationship type  Key attributes of all the participating entity types  Keys in table are  Primary key - combined key of all the “many” sides in relationship type  Foreign keys - Each “borrowed” key is a foreign key  Optimization: Often the table can be eliminated by extending the table for one side of the relationship

Mapping the ER Model to Relations(1)11 3. Mapping 1-1 Relationship Types  For each 1:1 binary relationship type, extend one of the tables for a participating entity type.  Primary key of the other entity type becomes a foreign key in this table  It is best to extend a table of an entity type with total participation  Add columns for each of the simple attributes of the relationship type  Optimization: Perhaps remove the table corresponding to the other entity type

Mapping the ER Model to Relations(1) Relationship Type Example  Each book is the basis for some film  For this ER schema, there would already by a Film table and a Book table from step 1, Extend the Film table to include the key of Book, which is BookTitle, Author.  Film(FilmID, Title, BookTitle, Author)  Optimize: remove Book table, add PubDate to Film Film TitleFilmID Book BookTitle Author Based On PubDate

Mapping the ER Model to Relations(1) to-Many Relationship Types  For each regular 1:N binary relationship type, there are several approaches  Option 1: Create a separate table for the relationship type Three tables result Key of relationship table is key of “many” side  Option 2: If the relationship is total, then extend a table corresponding to the ‘many’ entity type Two tables result (optimization)  Option 3: If the relationship is not total, extend a table with nullable attributes (sometimes not allowed for foreign keys) Two tables result (optimization)

Many Rel. Type Example, Option 1  Create a table for the relationship type  Add columns for each of the simple attributes of the relationship type  Add columns for each of the keys of the participating entity types  The key of the table is the key of the ‘many’ side  Example:  Create a Hires table  Store(Location, HoursOpen)  Hires(Location, EmployeeID)  Employee(EmployeeID, Location) Employee Hires EmployeeID Store Location Hours open

Mapping the ER Model to Relations(1) Many Rel. Type Example, Option 2 & 3  Do not have a table for the relationship type  Extend the table’s ‘many’ side with the primary key of the other participating entity type. This is a foreign key  Add columns for each of the simple attributes of the relationship type  Example:  Extend the Employee table with a Location column. Employee(EmployeeID, Location) Store(Location, Hours Open) Employee Hires EmployeeID Store Location Hours open

Mapping the ER Model to Relations(1)16 4. Column Renaming  Column names  Taken from attributes, usually unchanged  Two columns in a table cannot have the same name Must rename columns to retain uniqueness The renaming does not affect primary/foreign key status  Example  Must rename EmployeeID columns to disambiguate Supervises(Manager, Supervisee) Employee(EmployeeID) Employee Super- vises Supervisee Manager EmployeeID

Mapping the ER Model to Relations(1)17 5. Many-to-Many Relationship Types  Create a table for each binary M:N relationship type  The table has columns for  A column for each primary key attribute in a participating entity type. These are foreign keys  A column for each of the simple attribute of the relationship type  The primary key of the table is the union of the primary keys of the participating entity types

Mapping the ER Model to Relations(1)18 5. M:N Relationship Types Example  Film (FilmID, Title, RentalPrice)  Reserves(FilmID, CustomerID)  Customer(CustomerID, Name) Customer Reserves CustomerID Film TitleFilmID Name RentalPrice

Mapping the ER Model to Relations(1)19 5. Reflexive M:N Rel Types Example  Children (Parent, Child, Age)  Customer(CustomerID) Customer Children Parent Child CustomerID Age

Mapping the ER Model to Relations(1)20 6. N-ary Relationship Types  Create a table for each n-ary (n > 2) relationship type  Columns in the table are the primary keys of the participating entity types. (These are foreign keys)  Also include columns for each simple attribute of the relationship type  The primary key of the created table is the union of the primary keys of the participating entity types  Optimization: If the relationship type is (1,1) on a side, it may be possible to remove an entity table, placing its attributes in the table associated with the relationship

21 6. N-ary Relationship Types, Example  Reserves (CustomerID, FilmID, Location)  Rents (CustomerID, FilmID, TapeNum, Location, ReturnDate, AmountPaid, Status) Customer Rents VideoTape Film Copies Reserves Store TapeNum AmountPaidReturnDateStatus CustomerID Location FilmID (0,m)(0,n) (1,1) (0,n) (0,q) (0,j) (0,p)

Mapping the ER Model to Relations(1)22 7. Multivalued Attributes  Create a table for each multivalued attribute  The table has a column for each simple attribute of the multivalued attribute  Add columns for the primary key of the entity or relationship type to which the attribute belongs. (This is a foreign key)  The primary key is the combination of all the attributes  Example:  Director (FilmID, Name) Film FilmID Director