Translating ER Schema to Relational Model

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

Temple University – CIS Dept. CIS616– Principles of Database Systems
Relational Database Design Via ER Modelling
Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak entity set depends on the.
Text-Book Chapters (7 and 8) Entity-Relationship Model
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
CS34311 Translating ER Schema to Relational Model.
Murali Mani The Relational Model. Murali Mani Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still.
CS34311 The Entity- Relationship Model. CS34312 Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design Conceptual.
CS34311 The Entity- Relationship Model Part II.. CS34312 Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design.
Murali Mani The Entity- Relationship Model. Murali Mani Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design.
Entity-Relationship Model
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
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.
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.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 6: Entity-Relationship Model.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts DB Schema Design: the Entity-Relationship Model What’s the use of the E-R model? Entity Sets.
CS3431: C-Term The Entity- Relationship Model Part II. Instructor: Mohamed Eltabakh
1 Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
Entity Relationship Diagram (2)
Logical Design database design. Dr. Mohamed Osman Hegaz2 Conceptual Database Designing –Provides concepts that are close to the way many users perceive.
UNIT_2 1 DATABASE MANAGEMENT SYSTEM[DBMS] [Unit: 2] Prepared By Lavlesh Pandit SPCE MCA, Visnagar.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
CS34311 Translating ER Schema to Relational Model.
Software School of Hunan University Database Systems Design Part III : Mapping ER Diagram to Relational Schema.
1 The Entity- Relationship Model Instructor: Mohamed Eltabakh
1 The Entity- Relationship Model Instructor: Mohamed Eltabakh Part-2.
The Entity-Relationship Model
1 The Entity- Relationship Model Instructor: Mohamed Eltabakh Part-3.
CS34311 The Entity- Relationship Model Part III..
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
CS3431-B111 The Entity- Relationship Model Part II. Instructor: Mohamed Eltabakh
CS3431: C-Term Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
CS34311 Translating ER Schema to Relational Model.
Chapter 2: Entity-Relationship Model
COP Introduction to Database Structures
Translating ER Schema to Relational Model
Relational Database Design by ER- and EER-to- Relational Mapping
Entity-Relationship Model
Relational Database Design by ER- and EER-to-Relational Mapping
Chapter 6: Entity-Relationship Model
How to translate ER Model to Relational Model
The Entity-Relationship Model
Chapter 2: Entity-Relationship Model
From ER to Relational Model
Functional Dependencies and Normalization
The Entity-Relationship Model
Functional Dependencies and Normalization
Relational Database Design by ER- and EER-to-Relational Mapping
Session 2 Welcome: The seventh learning sequence
Chapter 6: Entity-Relationship Model
Relational Database Design by ER- and EER-to-Relational Mapping
Chapter 6: Entity-Relationship Model
Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak entity set depends on the.
Instructor: Mohamed Eltabakh
Chapter 6: Entity-Relationship Model
Relational Database Design by ER- and EER-to- Relational Mapping
Chapter 6: Entity-Relationship Model
Chapter 6: Entity-Relationship Model
Mapping an ERD to a Relational Database
Chapter 6: Entity-Relationship Model
Chapter 6: Entity-Relationship Model
Chapter 2: Entity-Relationship Model
Mapping an ERD to a Relational Database
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Relational Database Design by ER-to-Relational Mapping
Presentation transcript:

Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh meltabakh@cs.wpi.edu CS3431

First: Check Your Oracle Account cs3431

Translating ER Schema to Relational Schema Primary keys allow entity sets and relationship sets to be expressed uniformly as relational schemas Generally, each relational schema will have Number of columns corresponding to the number of attributes in ERD Column names that correspond to the attribute names cs3431

More optimizations will come … Basic Mapping Simple algorithm covers base the cases, Idea: Each entity set  separate relation Each relationship type  separate relation Define the primary keys as discussed in the ER Model More optimizations will come … cs3431

Example 1 Loan (load_number, amount) Customer (customer_id, customer_name, customer_street, customer_city) Borrower (customer_id, load_number) – Many-to-Many Relationship FOREIGN KEY Borrower (customer_id) REFERENCES Customer (customer_id) FOREIGN KEY Borrower (loan_number) REFERENCES Loan (loan_number) cs3431

Example 2 FOREIGN KEY Offers(dNumber) REFERENCES Dept(dNumber) Course offers Dept (dNumber, dName) Course (cNumber, cName) Offers (dNumber, cNumber) -- One-to-Many Relationship from Dept to Course FOREIGN KEY Offers(dNumber) REFERENCES Dept(dNumber) FOREIGN KEY Offers (cNumber) REFERENCES Course(cNumber) cs3431

Example 3 Product (pName, pNumber) Supplier (sName, sLoc) Consumer(cName, cLoc) Supply (sName, cName, pName, price, qty) FOREIGN KEY Supply(sName) REFERENCES Supplier(sName) FOREIGN KEY Supply (pName) REFERENCES Product(pName) FOREIGN KEY Supply (cName) REFERENCES Consumer(cName) cs3431

Example 4 Part(pNumber, pName) Contains(super_pNumber, sub_pNumber, quantity) FOREIGN KEY Contains (super_pNumber) REFERENCES Part (pNumber) FOREIGN KEY Contains (sub_pNumber) REFERENCES Part (pNumber) cs3431

Refinement I: Weak Entity Sets Weak entity set does not have its own key It must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the weak entity set A weak entity set is mapped to a relation with all its attributes + the key(s) of the identifying entity set(s) Primary key of the new relation is the: Identifying key(s) from identifying entity set(s), Plus Discriminator of the weak entity set Supporting relationship is not mapped in the relation model cs3431

Example 5 Dept(dNumber, dName) Course(dNumber, cNumber, cName) FOREIGN KEY Course(dNumber) REFERENCES Dept(dNumber) cs3431

Refinement II: One-to-Many & Many-to-One Cardinalities Many-to-one and one-to-many relationship sets can be represented by adding an extra attribute to the “many” side, containing the primary key of the “one” side This transferred primary key becomes a foreign key The relationship itself is not mapped to the relational model Any attributes on the relationship go to the “Many” side Course offers cs3431

Compare this with Example 2 (this is a better representation) Course offers Dept (dNumber, dName) Course (cNumber, dnumber, cName) FOREIGN KEY Course(dNumber) REFERENCES Dept(dNumber) Compare this with Example 2 (this is a better representation) cs3431

Example 7 Part(pNumber, pName) SubPart(sub_pNumber, super_pNumber, quantity) FOREIGN KEY SubPart(super_pNumber) REFERENCES Part (pNumber) FOREIGN KEY SubPart(sub_pNumber) REFERENCES Part (pNumber) Compare this with Example 4(Here the primary key of subPart is stronger) cs3431

Example 8 FOREIGN KEY Course(dNumber) REFERENCES Dept(dNumber) offers Open head (one and must be one) Dept (dNumber, dName) Course (cNumber, dnumber, cName) FOREIGN KEY Course(dNumber) REFERENCES Dept(dNumber) Compare this with Example 6 -- In Example 6: Course.dnumber can be null --In Example 8: Course.dnumber cannot be null cs3431

Refinement III: One-to-One Cardinalities One-to-one relationship sets can be represented by adding the primary key of either sides to the other side This transferred primary key becomes a foreign key The relationship itself is not mapped to the relational model Any attributes on the relationship go to the side receiving the transferred primary key Player pName pID Storage area Number Location size owns StartDate cs3431

Example 9 Player(pID, pNumber) pName pID Storage area Number Location size owns StartDate Player(pID, pNumber) StorageArea(Number, pID, startDate, Location, size) FOREIGN KEY StorageArea(pID) REFERENCES Player(pID) cs3431

Refinement IV: Composite & Derived Attributes sNum sName Student sAge address street city state Mapping strategy (Composite): Include an attribute for every primitive component of the composite attribute in the entity Mapping strategy (Derived): Mapped as is (enforced later using triggers) Student(sNum, sName, sAge, street, city, address) cs3431

Refinement V: Multi-valued Attributes sNum sName Student major sAge address street city state Mapping strategy: Represented as a relation by itself. The primary key of the relation = Attribute + the primary key of the main entity set Student(sNum, sName, sAge, street, city, address) StudentMajor(sNum, major) FOREIGN KEY StudentMajor (sNum) REFERENCES Student (sNum) cs3431

Refinement VI: ISA Relationships ISA is a one-to-one relationship BUT the sub-class entity sets inherit attributes from the super-class entity set That is why it does not follow the one-to-one rules Basically many ways for the mapping depending on whether it is total vs. partial and overlapping vs. disjoint Super-class key is always the primary key

ISA Relationship : Method 1 (Relation for each Entity Set) Student (sNumber, sName) UGStudent (sNumber, year) GradStudent (sNumber, program) PRIMARY KEY (Student) = <sNumber> PRIMARY KEY (UGStudent) = <sNumber> PRIMARY KEY (GradStudent) = <sNumber> FOREIGN KEY UGStudent (sNumber) REFERENCES Student (sNumber) An UGStudent will be represented in both Student relation as well as UGStudent relation A GStudent will be represented in both Student relation as well as GStudent relation

ISA Relationship : Method 2 (One Relation for All) Student (sNumber, sName, year, program) PRIMARY KEY (Student) = <sNumber> Note: There will be null values in the relation. cs3431

ISA Relationship : Method 3 (Relations only for SubClasses) Any student will be represented in only one or possibly both relations as appropriate Assumes total relationship UGStudent (sNumber, sName, year) GradStudent (sNumber, sName, program) PRIMARY KEY (UGStudent) = <sNumber> PRIMARY KEY (GradStudent) = <sNumber> cs3431

ISA Relationship : Method 4 (Relation for each combination) Any student will be represented in only one of the relations as appropriate. Student (sNumber, sName) UGStudent (sNumber, sName, year) GradStudent (sNumber, sName, program) UGGradStudent (sNumber, sName, year, program) PRIMARY KEY (Student) = <sNumber> PRIMARY KEY (UGStudent) = <sNumber> PRIMARY KEY (GradStudent) = <sNumber> PRIMARY KEY (UGGradStudent) = <sNumber>

Mapping from ER model to Relational model: Summary Basic algorithm covers the main cases Refinement I : Weak Entity Sets Refinement II : One-to-Many Relationships Refinement III : One-to-One Relationships Refinement IV : Composite & Derived Attributes Refinement V : Multi-Valued Attributes Refinement VI : ISA Relationships cs3431

What about an Exercise cs3431