ER-to-Relational Mapping

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Review Session ER and Relational –ER  Relational –Constraints, Weak Entities, Aggregation, ISA Relational Algebra  Relational Calculus –Selections/Projections/Joins/Division.
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.
1 Key Constraints Consider Works_In: An employee can work in many departments; a dept can have many employees. In contrast, each dept has at most one manager,
The Entity-Relationship (ER) Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
The Entity-Relationship Model
Comp3300/fall021 The Entity-Relationship Model Chapter 2 What are the steps in designing a database ? Why is the ER model used to create an initial design?
The Entity-Relationship Model
The Entity-Relationship Model Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Conceptual Design and The Entity-Relationship Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 176 Database Systems I The Entity-Relationship Model.
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.) –What are the entities.
Modeling Your Data Chapter 2. Overview of Database Design Conceptual design: –What are the entities and relationships in the enterprise? – What information.
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.
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.
1 The Entity-Relationship Model Chapter 2. 2 Database Design Process  Requirement collection and analysis  DB requirements and functional requirements.
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design : (ER Model is used at this stage.)  What are the entities.
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,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Chapter 2.  Conceptual design: (ER Model is used at this stage.) ◦ What are the entities and relationships in the enterprise? ◦ What information about.
CMPT 258 Database Systems The Entity-Relationship Model Part II (Chapter 2)
Christoph F. Eick: Designing E/R Diagrams 1 The Entity-Relationship Model Chapter 3+4.
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.
09/03/2009Lipyeow Lim -- University of Hawaii at Manoa 1 ICS 321 Fall 2009 Introduction to Database Design Asst. Prof. Lipyeow Lim Information & Computer.
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.
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)
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.
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.
A short review on entity- relationship modelling.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Introduction to Database Design
COP Introduction to Database Structures
Logical DB Design: ER to Relational
The Entity-Relationship Model
MODELS OF DATABASE AND DATABASE DESIGN
The Entity-Relationship Model
The Entity-Relationship Model
Instructor: Elke Rundensteiner
From ER to Relational Model
The Entity-Relationship (ER) Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
Question Which of the following plays an important role in representing information about the real world in a database? Explain briefly 1)DDL.
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship (ER) Model
Presentation transcript:

ER-to-Relational Mapping Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 3

Regular Entity Set LName FName SSN MidInit Sex Employees Address Create relation for the entity set; include all attributes. Choose one of the key attributes as the PK. Employees Address Salary Employee (SSN, FName, MidInit, LName, Sex, Address, Salary)

Relationship Set – No Key or Participation Constraints Name Since DName Create relation for relationship set. Include as FKs the PKs of each participating entity set. Include descriptive attributes of relationship set. Relation’s PK is collection of PK attributes from participating entity sets. SSN Lot Budget DID WorksIn2 Employees Departments Address Locations Create relations for the entity sets: Employees (SSN, Name, Lot) Departments (DID, DName, Budget) Locations (Address, Capacity) and a relation for the relationship set: WorksIn2 (SSN, DID, Address, Since) SSN is FK that references Employees. DID is FK that references Departments. Address is FK that references Locations. Capacity Figure 3.10

Roles supervisor Employees ReportsTo SSN Name Lot To represent the ReportsTo relationship set, create meaningful attribute names for SSN to represent the two different roles played by Employees. subordinate Create relation for the entity set: Employees (SSN, Name, Lot) and relation for the relationship set: ReportsTo (SupervisorSSN, SubordinateSSN) SupervisorSSN is FK that references SSN in Employees. SubordinateSSN is FK that references SSN in Employees. Figure 3.11

Relationship Set – Key Constraint Approach 1 Suppose relationship set has n participating entity sets of which m are linked via arrows. The key for any one of those m entity sets is a candidate key for relation representing relationship set. Name Since DName SSN Lot Budget DID Manages Employees Departments Figure 3.12 Create relations for the entity sets: Employees (SSN, Name, Lot) Departments (DID, DName, DBudget) and a relation for the relationship set: Manages (SSN, DID, Since) SSN is FK that references Employees. DID is FK that references Departments. Why not have (SSN, DID) as the PK for Manages?

Relationship Set – Key Constraint Approach 2 Do not define separate relation for relationship set. Relationship is represented in relation corresponding to entity set with the key. Name Since DName SSN Lot Budget DID Manages Employees Departments Figure 3.12 Create relations for the entity sets. Add SSN to Departments to represent relationship set; also include the relationship’s descriptive attribute. Employees (SSN, Name, Lot) Departments (DID, DName, DBudget, SSN, Since) SSN is FK that references Employees. Note: Book renamed the Departments relation DeptMgr.

Relationship Set – Participation Constraint Name Since DName SSN Lot Budget DID Manages Employees Departments Each department has exactly one manager: Participation constraint: Each department must have at least 1 manager. Key constraint: Each department may have at most 1 manager. WorksIn Figure 3.13 Since

Participation Constraint (continued) Note: We’re using the 2nd approach for representing the key constraint. Why would the 1st approach not work in this case? Employees Manages SSN Name Lot DID DName Budget Since Departments WorksIn Employees (SSN, Name, Lot) DeptMgr (DID, DName, Budget, SSN, Since) SSN is FK that references Employees; cannot be null. WorksIn (SSN, DID, Since) SSN is FK that references Employees; every SSN in Employees must appear in WorksIn. DID is FK that references DeptMgr; every DID in DeptMgr must appear in WorksIn. Figure 3.13

Weak Entity Set Name Create relation for weak entity set. Include as FKs the PKs of the owner entity set. PK for new relation is owner’s PK and weak entity set’s partial key. Use 2nd approach given earlier to represent 1:N relationship set between owner and weak entity set. Specify “on delete cascade” to indicate existence dependence. Cost SSN Lot PName Age Employees Policy Dependents Figure 3.14 Define relation for Employees: Employees (SSN, Name, Lot) and relation for Dependents entity set plus Policy relationship set: DepPolicy (SSN, PName, Age, Cost) SSN is FK that references Employees; on delete cascade.

Class Hierarchy Approach 1 Name Lot SSN Employee Map each entity set to a relation. For each subclass entity set, include the PK of the superclass. The subclass’s PK is the same as the superclass’s PK and is a FK; specify “on delete cascade”. ISA HoursWorked HourlyEmps ContractEmps Employee (SSN, Name, Lot) HourlyEmps (SSN, HourlyWages,HoursWorked) SSN is FK that references Employee; on delete cascade. ContractEmps (SSN, ContractID) HourlyWages ContractID Figure 3.15

Class Hierarchy Approach 2 Name Lot SSN Employee Map only the subclass entity sets to relations. For each subclass entity set, include the PK of the superclass. ISA HoursWorked HourlyEmps ContractEmps HourlyWages ContractID HourlyEmps (SSN, Name, Lot, HourlyWages, HoursWorked) ContractEmps (SSN, Name, Lot, ContractID) Figure 3.15

Aggregation Name Lot SSN Employees Employees (SSN, Name, Lot) Until Projects SSN Name Lot Monitors Until Sponsors Departments Since PID StartedOn PBudget DID DName Budget Employees (SSN, Name, Lot) Projects (PID. StartedOn, PBudget) Departments (DID, DName, Budget) Sponsors (PID, DID, Since) Every PID in Projects must appear in Sponsors. Monitors (SSN, DID, PID, Until) Note that the relation representing the Monitors relationship set includes the key attributes of the Sponsors relation and the descriptive attributes of the Monitors relationship set. Figure 3.16