Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 Mapping E/R Diagrams to Relational Database Schemas Second Half of Chapter.

Slides:



Advertisements
Similar presentations
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,
Advertisements

R ELATIONAL M ODEL TO SQL Data Model. 22 C ONCEPTUAL D ESIGN : ER TO R ELATIONAL TO SQL How to represent Entity sets, Relationship sets, Attributes, Key.
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
The Entity-Relationship Model
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Book Chapter 3 (part 2 ) From ER to Relational Model.
1 541: Database Systems S. Muthu Muthukrishnan. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.)  What are the entities.
The Entity-Relationship (ER) Model
The Entity-Relationship Model
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Conceptual Design and The Entity-Relationship Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke. Edited by Keith Shomper, The Relational Model Chapter 3.
CSC 411/511: DBMS Design 1 1 Dr. Nan WangCSC411_L3_Relational Model 1 The Relational Model (Chapter 3)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 1 Raghu Ramakrishnan The Relational Model Chapter 3 Instructor: Mirsad Hadzikadic.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 176 Database Systems I The Entity-Relationship Model.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Modeling Your Data Chapter 2. Overview of Database Design Conceptual design: –What are the entities and relationships in the enterprise? – What information.
The Relational Model 198:541 Rutgers University. Why Study the Relational Model?  Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle,
Conceptual Design Using the Entity-Relationship (ER) Model
The Entity-Relationship (ER) Model CS541 Computer Science Department Rutgers University.
1 Data Modeling Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
1 Data Modeling Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
ER continued, and ER to Relational Mappings R&G Chapters 2, 3 Lecture 22.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
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,
1 The Relational Model Chapter 3. 2 Objectives  Representing data using the relational model.  Expressing integrity constraints on data.  Creating,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3 Modified by Donghui Zhang.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model  Vendors: IBM, Informix, Microsoft, Oracle, Sybase  Recent.
 Relational database: a set of relations.  Relation: made up of 2 parts: › Instance : a table, with rows and columns. #rows = cardinality, #fields =
1 The Entity-Relationship Model Chapter 6. 2 Database Design Process  Requirement collection and analysis  DB requirements and functional requirements.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
Christoph F. Eick: Designing E/R Diagrams 1 The Entity-Relationship Model Chapter 3+4.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
The Relational Model1 ER-to-Relational Mapping and Views.
ICS 321 Fall 2009 The Relational Model (ii) Asst. Prof. Lipyeow Lim Information and Computer Science Department University of Hawaii at Manoa 9/10/20091Lipyeow.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Management Systems,1 Conceptual Design Using the Entity-Relationship (ER) Model.
Mapping E/R Diagrams to Relational Database Schemas
CMPT 258 Database Systems The Relationship Model PartII (Chapter 3)
Lecture 3 Book Chapter 3 (part 2 ) From ER to Relational.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 3 The Relational Model.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
The Entity-Relationship (ER) Model. Overview of db design Requirement analysis – Data to be stored – Applications to be built – Operations (most frequent)
CSC 411/511: DBMS Design 1 1 Dr. Nan WangCSC411_L2_ER Model 1 The Entity-Relationship Model (Chapter 2)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #5 (E-R  Relational, Cont.) Instructor: Chen Li.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Multi-billion dollar industry, $15+ bill in  Vendors:
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Logical DB Design: ER to Relational
The Entity-Relationship Model
COP4710 Database Systems Relational Model.
MODELS OF DATABASE AND DATABASE DESIGN
ER-to-Relational Mapping
The Entity-Relationship Model
Instructor: Elke Rundensteiner
From ER to Relational Model
The Entity-Relationship Model
CS4433 Database Systems Relational Model.
The Entity-Relationship Model
Presentation transcript:

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 Mapping E/R Diagrams to Relational Database Schemas Second Half of Chapter 3

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 2 E/R  Relation Model (Example) lot name dname budgetdid since name dname budgetdid since Manages since Departments Employees ssn Works_In (0,*) (1,1) Contract_Emps hourly_wages Hourly_Emps contractid hours_worked 

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 3 Dr. Eick’s Default Mapping E/R  Relational Data Model 1.For each entity type create a relation with the attributes associated with the entity type. Choose a primary key for the defined relation; if the entity type is weak, delay choosing primary keys until all identifying relationships are mapped. 2.For each relationship type create a relation that contains the roles as well as the attributes of the relationship type. Define referential integrity constraints with respect to the mapped roles. Exception: If there is a (1,1) cardinality constraint do not generate a separate relation, but rather associate the relationship information with the relation of this participating entity type. 3.For each sub-type create a relation that contains the attributes of the entity type as well as the primary key of the most general super class of this entity type (which also will be the primary key of the generated relation). Define referential integrity constraints with respect to the direct super class of the mapped entity type.

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 4 Logical DB Design: ER to Relational 1. Entity Types to Tables. CREATE TABLE Employees (ssn CHAR (9), name CHAR (20), lot INTEGER, PRIMARY KEY (ssn)) Employees ssn name lot

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 5 2. Relationship Types to Tables In translating a relationship set to a relation, attributes of the relation must include: Keys for each participating entity set (as foreign keys). This set of attributes forms a superkey for the relation. All descriptive attributes. CREATE TABLE Works_In( ssn CHAR (9), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments)

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 6 Translating ER Diagrams with Key Constraints Map relationship to a table: Note that did is the key now! Separate tables for Employees and Departments. Since each department has a unique manager, we could instead combine Manages and Departments. CREATE TABLE Manages( ssn CHAR(9), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, manager CHAR(9), since DATE, PRIMARY KEY (did), FOREIGN KEY (manager) REFERENCES Employees)

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 7 Review: Weak Entities A weak entity can be identified uniquely only by considering the primary key of another ( owner ) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (1 owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. lot name age dname Dependents Employees ssn Policy cost Dependents Policy (1,1) (0,*) Parent

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 8 Translating Weak Entity Types Weak entity set and identifying relationship set are translated into a single table --- it has a (1,1) cardinality constraint. CREATE TABLE Dep_Policy ( dname CHAR(20), age INTEGER, cost REAL, parent CHAR(9) NOT NULL, PRIMARY KEY (pname, ssn), FOREIGN KEY (parent) REFERENCES Employees, ON DELETE CASCADE )

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 9 Review: ISA Hierarchies Contract_Emps name ssn Employees lot hourly_wages ISA Hourly_Emps contractid hours_worked As in C++, or other PLs, attributes are inherited. If we declare A ISA B, every A entity is also considered to be a B entity. Overlap constraints : Can Joe be an Hourly_Emps as well as a Contract_Emps entity? ( Allowed/disallowed ) Covering constraints : Does every Employees entity also have to be an Hourly_Emps or a Contract_Emps entity? (Yes/no)

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions Translating ISA Hierarchies to Tables General approach: 3 relations: Employees, Hourly_Emps and Contract_Emps. Hourly_Emps : Every employee is recorded in Employees. For hourly emps, extra info recorded in Hourly_Emps ( hourly_wages, hours_worked, ssn) ; must delete Hourly_Emps tuple if referenced Employees tuple is deleted). Queries involving all employees easy, those involving just Hourly_Emps require a join to get some attributes. Alternative: Just Hourly_Emps and Contract_Emps. Hourly_Emps : ssn, name, lot, hourly_wages, hours_worked. Each employee must be in one of these two subclasses.

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 11 Dr. Eick’s Default Mapping E/R  Relational Data Model 1.For each entity type create a relation with the attributes associated with the entity type. Choose a primary key for the defined relation; if the entity type is weak, delay choosing primary keys until all identifying relationships are mapped. 2.For each relationship type create a relation that contains the roles as well as the attributes of the relationship type. Define referential integrity constraints with respect to the mapped roles. Exception: If there is a (1,1) cardinality constraint do not generate a separate relation, but rather associate the relationship information with the relation of this participating entity type. 3.For each sub-type create a relation that contains the attributes of the entity type as well as the primary key of the most general super class of this entity type (which also will be the primary key of the generated relation). Define referential integrity constraints with respect to the direct super class of the mapped entity type.

Male Female Person name ssn Wedding (0,*) E/R Diagram to be mapped occurred (0,*) fromto (1,1) Is-insured Company name amount (0,*) location  husband wife Con#

Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 13 Mapping of the Multi-Wedding E/R Diagram to a Relational Schema Person(ssn,name) Company(name,location) Male_Person(ssn)Female_Person(ssn) Wedding(husband,wife,from,to) Is-Insured(hssn,wssn,from,company, amount, Con#) Correct Syntax: FOREIGN KEY (hssn,wssn,from) REFERENCES Wedding(husband,wife,from)