Transforming E/R to Relational Model.

Slides:



Advertisements
Similar presentations
High-Level Database Models Spring 2011 Instructor: Hassan Khosravi.
Advertisements

Relational Database Design Via ER Modelling
Boyce-Codd NF Takahiko Saito Spring 2005 CS 157A.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 6 A First Course in Database Systems.
Functional Dependencies - Example
Database Systems The Relational Data Model
Relational Algebra.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
Midterm Review II. Redundancy. –Information may be repeated unnecessarily in several tuples. –E.g. length and filmType. Update anomalies. –We may change.
Design Principles: Faithfulness
Entity-Relationship Model. The process of designing a database begins with: –an analysis of what information the database must hold, and –the relationships.
Design Principles: Faithfulness
Relational Model CS 157A Prof. Sin-Min Lee By Truc Truong.
The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file.
ER Modeling An E-R model is a conceptual (or logical) data model that includes –Entity (classes) –Attributes of each entity –Relationship types between.
Additional ODL Concepts OO Model to Relational Model Object-Relational Design OO vs OR.
Movies length titleyearfilmType Voices isa Cartoons isa MurderMystery weapon toStar Our Movie Example.
Entity-Relationship Model
The principal problem that we encounter is redundancy, where a fact is repeated in more than one tuple. Most common cause: attempts to group into one relation.
Operations in the Relational Model These operation can be expressed in an algebra, called “relational algebra”. In this algebra relations are the operands.
From E/R Diagrams to Relations. The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes.
The Entity-Relationship Data Model
Mapping from E-R Model to Relational Model Yong Choi School of Business CSUB.
1 The Entity-Relationship Data Model Chapter 2 (Database Design)
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
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
Mapping from Data Model (ERD) to Relational Model Yong Choi School of Business CSUB.
Database Systems The Entity-Relationship Model
Mapping from Data Model (ERD) to Relational Model
Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006.
Introduction to Indexes. Indexes An index on an attribute A of a relation is a data structure that makes it efficient to find those tuples that have a.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
Operations in the Relational Model COP 4720 Lecture 8 Lecture Notes.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 4 Introduction to a First Course in Database Systems.
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 5 Introduction to a First Course in Database Systems.
Functional Dependencies. Babies Exercise 2.2.5: At a birth, there is one baby (twins would be represented by two births), one mother, any number of nurses,
Databases : Functional Dependencies 2007, Fall Pusan National University Ki-Joune Li.
© D. Wong Ch. 3 (part 1)  Relational Model basics  From E/R diagram to Relations.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Modeling: Entity-Relationship Diagrams
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
ER Diagrams and Relational Model CS 174a (Winter 2015)
Hele-Mai Haav: CSC210-Spring*01 CSC230-Spring*03 Database Design.
COP Introduction to Database Structures
ERwin.
Logical Database Design and the Rational Model
Business System Development
Chap 3. High-Level Database Models
COP Introduction to Database Structures
COP4710 Database Systems E-R Model.
Entity-Relationship Model
Chapter 7: Entity-Relationship Model
Relational Database Design by ER- and EER-to-Relational Mapping
ER- and EER-to-Relational
INF385T: Information Modeling — Class 11 Relational Database Design from ER Models Presented November 2 Karen Wickett,
Order Database – ER Diagram
Design Theory for Relational Databases
Relational Database Design by ER- and EER-to-Relational Mapping
More Relation Operations
Initial Design of Entity Types: EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT Gender.
Session 2 Welcome: The fifth learning sequence
Relational Database Design by ER- and EER-to-Relational Mapping
Database Dr. Roueida Mohammed.
Session 5: Weak Entity Sets and ER Model to Relational ( )
Chapter 6b: Database Design Using the E-R Model
Design Theory for Relational Databases
Presentation transcript:

Transforming E/R to Relational Model.

From E/R Diagrams to Relational Data Model Designs To a first approximation, converting an E/R design to a relational database schema is straightforward: Turn each entity set into a relation with the same set of attributes; and Replace a relationship by a relation whose attributes are the keys for the connected entity sets.

From E/R Diagrams to Relational Data Model Designs While these two rules cover much of the ground, there are also several special situations that we need to deal with, including: Weak entity sets cannot be translated straightforwardly to relations. “Isa” relationships and sub classes require careful treatment. Sometime we do well to combine two relations, especially the relations for an entity set E and the relation that comes from a many-one relationship from E to some other entity set.

From E/R Diagrams to Relational Data Model Designs 1. From Entity sets to relations: For each non-weak entity set, we shall create a relation of the same name and with the same set of attributes This relation will not have any indication of the relationships in which the entity set participates; we’ll handle relationships with separate relations.

From E/R Diagrams to Relational Data Model Designs title year name address Stars-in Stars Movies length filmtype Owns name address Studios

From E/R Diagrams to Relational Data Model Designs Consider the three entity sets Movies, Stars and Studios. Movies(title, year, length, filmType) title year length filmType Star Wars 1977 124 Color Mighty Duck 1991 104 Wayne’s War 1992 95

From E/R Diagrams to Relational Data Model Designs Next, consider the entity set Stars from the E/R Diagram. There are two attributes name and address. Thus, we would expect the corresponding Stars relation to have the schema Star(name, address) and for a typical instance of the relation to look like: name address John Smith 123 Maple St……Hollywood Steve Toss 456 Oak Rd…..Brentwood

From E/R Diagrams to Relational Data Model Designs 2. From E/R Relationships to Relations: Relationships in the E/R model are also represented by relations. The relation for a given relationship R has the following attribute. For each entity set involved in relationship R, we take its key attributes or attributes as part of the schema of the relation R. If the relationship has attributes, then these are also attributes of relation R. If one entity set is involved several times in a relationship, in different roles, then its key attributes each appear as many times as there are roles. We must rename the attributes to avoid name duplication. More generally, should the same attributes name appear twice or more among the attributes of R itself and the keys of the entity sets involved in relationship R, then we need to rename to avoid duplication.

From E/R Diagrams to Relational Data Model Designs 2. From E/R Relationships to Relations con’t: Consider the relationship Owns. This relationship connect entity sets Movies and Studios. Thus, for the schema of relation Owns we use the key for Movies which is title and year, and the key of Studios, which is name. That is the schema is: Owns (title, year, studioName). A sameple instance of this relation is: Title Year StudioName Star Wars 1977 Fox Mighty Duck 1991 Disney We have chosen the attribute studioName for clarity, it corresponds to the attribute name of Studios

From E/R Diagrams to Relational Data Model Designs Similarly, the relationship Stars-in can be transformed into a relation with the attributes title and year (the key for Movies) and attribute starName which is the key for entity set Stars. Shows below is a sample relation of Stars-In. Title Year StarName Star Wars 1977 Carrie Fisher Star Wars 1977 Mark Hamil Star Wars 1977 Harry Ford Mighty Duck 1991 Dana Carvey

From E/R Diagrams to Relational Data Model Designs Multiway relationships are also easy to convert to relations. Consider the four way relationships Contracts involving a star, movie and two studios – the first holding the star’s contract and the second contracting for that star’s services in that movie. We represent this relationship by a relation Contracts whose schema consists of the attributes from the keys of the following four entity sets: The key starName for the star The key consisting of attributes title and year for the movie The key studioOfStar indicating the name of the first studio; recall we assume the sudio name is a key for the entity set Studios. The key producingStudio indicating the name of the studio that will produce the movie using that star. That is the schema is: Contracts(starName, title, year, studioOfStar, producingStudio) Notice that we have been inventive in choosing attribute names for our relation schema avoiding “name” for any attribute since it would be unobvious whether that referred to a star’s name or studio’s name and in the later case which studio.

From E/R Diagrams to Relational Data Model Designs 3. Combining Relations: Combining relation Movies with relation Owns (title, year, filmType, studioName)