1 Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh

Slides:



Advertisements
Similar presentations
Chapter 2: Entity-Relationship Model
Advertisements

ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
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.
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.
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.
1 Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of an E-R Database.
CS34311 The Entity- Relationship Model Part II.. CS34312 Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design.
Chapter 2: Entity-Relationship Model (Continued)
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com The following slides are.
©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.
Entity-Relationship Model
Mapping ERM to relational database
Ch 6: ER to Relational Mapping
Chapter 5 1 © Prentice Hall, 2002 Chapter 5: Transforming EER Diagrams into Relations Mapping Regular Entities to Relations 1. Simple attributes: E-R attributes.
Notes by Ankur Shukla Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys.
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
Entity-Relationship Model
Module Title? Data Base Design 30/6/2007 Entity Relationship Diagrams (ERDs)
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Entity-Relationship.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
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.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
6.1 Chapter 6: Database Design and the ER Model Skip 6.5.3, 6.10, 6.11.
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.
1 Session 2 Welcome: The seventh learning sequence “ Reduction of an EER schema to tables“ Recap : In the previous learning sequence, we discussed the.
©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.
Chapter 9: Logical Database Design and the Relational Model (ERD Mapping)
CS3431: C-Term The Entity- Relationship Model Part II. Instructor: Mohamed Eltabakh
Chapter 2 : Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of.
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)
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.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
CS157A Lecture 4 ER Model 2 Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Database Design Slide 1 Database Design Lecture 7 part 2 Mapping ERD to Tables.
Mapping ER Diagrams to Tables
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
Introduction to Database Systems
CS3431-B111 The Entity- Relationship Model Part II. Instructor: Mohamed Eltabakh
Lecture 26 Enterprise Systems Development ( CSC447 ) COMSATS Islamabad Muhammad Usman, Assistant Professor.
CS3431: C-Term Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
CS34311 Translating ER Schema to Relational Model.
Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of an.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
Chapter 2: Entity-Relationship Model
Translating ER Schema to Relational Model
Translating ER Schema to Relational Model
Relational Database Design by ER- and EER-to-Relational Mapping
Session 2 Welcome: The seventh learning sequence
Chapter 6: Entity-Relationship Model
Mapping an ERD to a Relational Database
Presentation transcript:

1 Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh

First: Check Your Oracle Account cs34312

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 cs34313

What is the Relational Model ??? cs34314

5 Basic Rule for Mapping Each entity set  separate relation Relationships Many-to-Many  always separate relation Others (One-to-Many & One-to-One) If contributes with a key  map to separate relation If not  is not mapped to separate relations More details will come …

Rule I: One-to-Many & Many- to-One Cardinalities PK of “One-side” moves to the “many-side” This transferred primary key becomes a foreign key The relationship itself is not mapped to a table Any attributes on the relationship go to the “Many” side cs34316 Course offers

Example 1 Dept (dNumber, dName) Course (cNumber, dnumber, cName) FOREIGN KEY Course(dNumber) REFERENCES Dept(dNumber) cs34317 Course offers

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

Rule I: One-to-Many & Many- to-One With Key: Example 3 Dept (dNumber, dName) Course (cNumber, dnumber, cName) Offer(cNumber, term) FOREIGN KEY Course(dNumber) REFERENCES Dept(dNumber) Foreign key Offer(cNumber) References Course(cNumber) 9 Course offer term Relationship maps to separate relation + PK from “many-side” If combined with “Course”  Creates redundancy Do not add dnumber…It’s redundancy  Known from cNumber

Example 4: Apply one-to-many Rule to recursive relationship Part(pNumber, pName, superPartNumber, quantity) FOREIGN KEY Part(superPartNumber) REFERENCES Part (pNumber) cs Nothing New….

Rule II: One-to-One Cardinalities PK of either sides go 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 cs Player pName pID Storage area Number Location size owns StartDate

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

Example 5 (another design) Player(pID, pNumber, StorageNumber, StartDate) StorageArea(Number, Location, size) FOREIGN KEY Player(StorageNumber) REFERENCES StorageArea(Number) cs Player pName pID Storage area Number Location size owns StartDate

Rule III: Many-to-Many Relationship Each entity set maps to a relation The relationship also maps to a relation Key of relationship = keys coming from both sides + Any key of the relationship itself 14 Loan (load_number, amount) Customer (customer_id, customer_name, customer_street, customer_city) Borrower (customer_id, load_number, Date) Date

Rule IV: 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 15 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

Example 6 Dept(dNumber, dName) Course(dNumber, cNumber, cName) FOREIGN KEY Course(dNumber) REFERENCES Dept(dNumber) cs343116

Exercise cs Author(name, address, URL) Book(ISBN, title, year, price, publisher_Name) WrittenBy(name, address, ISBN) Publisher(name, address, phone, URL) Warehouse(code, phone, address) Stocks(ISBN, WH_code, number) Shopping-Basket(basketID, ) basketContains(ISBN, basketID, number) Customer( , name, address, phone)

cs Rule V: Composite & Derived Attributes Student sNamesNum sAge statestreet address city Mapping strategy (Composite): Include only the 2 nd level attributes Mapping strategy (Derived): Mapped as is (enforced later using triggers) Student(sNum, sName, sAge, street, city, state)

cs Rule VI: Multi-valued Attributes Student sNamesNum sAge statestreet address city Mapping strategy: Becomes a relation by itself. The primary key of that relation = Attribute + the PK of the main entity set Student(sNum, sName, sAge, street, city, address) StudentMajor(sNum, major) FOREIGN KEY StudentMajor (sNum) REFERENCES Student (sNum) major

Rule VII: 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 20

21 ISA Relationship : Method 1 (Relation for each Entity Set) Person(SSN, Name, DoB) Student(SSN, GPA, StartDate) Employee(SSN, Department, Salary) In this design: Each student has two records (one in Person, and one in Student)  They complete each other Each employee has two records (one in Person, and one in Employee)  They complete each other FOREIGN KEY Student(SSN) REFERENCES Person(SSN) FOREIGN KEY Employee(SSN) REFERENCES Person(SSN)

cs ISA Relationship : Method 2 (One Relation for All) Person(SSN, Name, DoB, GPA, StartDate, Salary, Department) In this design: Any person will have only one record But, there will be many null values

cs ISA Relationship : Method 3 (Relations only for SubClasses) Good for total & disjoint type Cannot be used for partial (otherwise some entities will not fit in any relation) If the relationship is overlapping  there will some redundancy Student(SSN, Name, DoB, GPA, StartDate) Employee(SSN, Name, DoB, Department, Salary) >> Create a relation for each subclass only (not the parent)

24 ISA Relationship : Method 4 (Relation for each combination) Student(SSN, Name, DoB, GPA, StartDate) Employee(SSN, Name, DoB, Department, Salary) StudentEmp(SSN, Name, DoB, GPA, StartDate, Salary, Department) In this design: Any person will have only one record in only one of the tables Good for overlapping relationship If relationship is total  The above relations are enough If relationship is partial  we need a relation for “Person(SSN, Name, DoB)”

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