Translating an ER Diagram to a Relational Schema

Similar documents
Agent 7 which languages? skills?

High-Level Database Models (ii)

High Level Database Models

Conceptual Design. The Entity-Relationship (ER) Model

The Entity-Relationship Model

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

From ER to Relational Model. Book Chapter 3 (part 2 )

The Relational Model. Chapter 3

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

The Relational Model (ii)

The Relational Model 2. Week 3

The Entity-Relationship Model. Overview of Database Design

Introduction to Data Management. Lecture #5 (E-R Relational, Cont.)

Introduction to Databases

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Database Management Systems. Chapter 3 Part 2

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Advance Database Management System

Introduction to Data Management. Lecture #6 E-Rà Relational Mapping (Cont.)

Database Applications (15-415)

ER to Relational Mapping

Database Systems ( 資料庫系統 )

Database Design & Deployment

CSC 261/461 Database Systems Lecture 10

ER-to-Relational Mapping

The Relational Model

Converting ER to Relational Schema

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

MIT Database Management Systems Lesson 03: ER-to-Relational Mapping

OVERVIEW OF DATABASE DEVELOPMENT

Chapter 9: Relational DB Design byer/eer to Relational Mapping Relational Database Design Using ER-to- Relational Mapping Mapping EER Model

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

Ch 9: Mapping EER to Relational. Follow a seven-step algorithm to convert the basic ER model constructs into relations steps 1-7

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

LAB 3 Notes. Codd proposed the relational model in 70 Main advantage of Relational Model : Simple representation (relationstables(row,

Relational DB Design by ER- and EER-to-Relational Mapping Design & Analysis of Database Systems

Conceptual Design. The Entity-Relationship (ER) Model

CSC 261/461 Database Systems Lecture 8. Spring 2018

CSC 261/461 Database Systems Lecture 8. Fall 2017

Contents. Database. Information Policy. C03. Entity Relationship Model WKU-IP-C03 Database / Entity Relationship Model

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

Database Applications (15-415)

ER to Relational Mapping. ER Model: Overview

The Entity-Relationship Model (ER Model) - Part 2

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Objectives of logical design... Transforming the ERD diagram into relations. Relational database components. Mapping a composite attribute

Topic 5: Mapping of EER Diagrams to Relations

ENTITY-RELATIONSHIP MODEL. CS 564- Spring 2018

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

CSE 530A. ER Model. Washington University Fall 2013

CSE 530A. ER Model to Relational Schema. Washington University Fall 2013

Database Systems. Course Administration

Database Management System 6 ER Modeling...

Introduction to Database Design

CS W Introduction to Databases Spring Computer Science Department Columbia University

Conceptual Design with ER Model

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

The Relational Model

Overview of db design Requirement analysis Data to be stored Applications to be built Operations (most frequent) subject to performance requirement

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

Database Systems. Lecture2:E-R model. Juan Huo( 霍娟 )

Integrity constraints, relationships. CS634 Lecture 2

CIS 330: Applied Database Systems

Introduction to Database Design

CS 405G: Introduction to Database Systems

Outline. Note 1. CSIE30600 Database Systems ER/EER to Relational Mapping 2

1/24/2012. Chapter 7 Outline. Chapter 7 Outline (cont d.) CS 440: Database Management Systems

Overview of the Class and Introduction to DB schemas and queries. Lois Delcambre

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

The Relational Model. Week 2

The Entity-Relationship (ER) Model 2

Where Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams

Elements of the E-R Model

ER Model. Objectives (2/2) Electricite Du Laos (EDL) Dr. Kanda Runapongsa Saikaew, Computer Engineering, KKU 1

E-R Diagram to Relational Schema. Translating Entity-Relationship to Relational Tables. Representing Weak Entity Sets. Representing Strong Entity Sets

Review The Big Picture

THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)

Database Management

From theory to practice. Designing Tables for an Oracle Database System. Sqlplus. Sqlplus. Technicalities. Add the following to your.

Database Design CENG 351

Translating Entity-Relationship to Relational Tables

Designing Tables for an Oracle Database System. From theory to practice

Announcements. Database Design. Database Design. Database Design Process. Entity / Relationship Diagrams. Introduction to Data Management CSE 344

DATABASE DESIGN I - 1DL300

Homework 2. Develop an EER model for the following situation using the EER diagram,

Data Modeling Using the Entity- Relationship Model Design & Analysis of Database Systems

Translating Entity-Relationship to Relational Tables

CSE 344 MAY 14 TH ENTITIES

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Representation in Relational Model.

Transcription:

Translating an ER Diagram to a Relational Schema CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 1

Translate each entity set into a table, with keys. Entity set: represented as a table has a key which becomes a key for the table All single-valued attributes become attributes of the table Create a new table for any multi-valued attributes If employee has many offices add an extra table. E-Name Employee Office CREATE TABLE Employee ( CHAR(11), E-Name CHAR(20), Office INTEGER, PRIMARY KEY ()) Or delete Office from above and add: CREATE TABLE Emp-Office ( CHAR(11), Office INTEGER, PRIMARY KEY (, Office)) CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 2

Notice the key for the new table: Office- Assignment. Sample Data Project (P-number, P-, Due-Date) Employee (, E-Name, Office) 12 Smith O-105 15 Wei O-110 20 Jones O-112 Project (P-number, P-, Due-Date) Employee (, E-Name) 12 Smith 15 Wei Office-Assignment (, Office) 12 O-105 12 O-106 15 O-110 CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 3

What data do we need to record a relationship? Employee lot Team-member Team number start-date We must indicate which employee and which team we want to have connected (for each relationship). We need the key value for an employee and the key value for the team stored together to represent the relationship. Could be in an existing table that represents one of the involved entities or a new table (introduced to represent the relationship). We may want additional attributes about the relationship. We need: Team-rel (, number) CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 4

Employee lot 0..* Team-member 0..* Team number start-date Translate each many-to-many relationship set into a new table. Team-member (, number) with 2 foreign keys Team (number,, start-date) Employee (,, lot) CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 5

Translate one-to-many relationship set into a foreign key. (Or a separate table.) Employee office 0..* home 0..1 0..1 manager 0..1 Department code Add a foreign key to the many side of the relationship to represent a 1-to-many relationship set. Department (code, ) Employee (,, office, dept) dept is a foreign key (referencing Department.code) Notice: and code are side by side, in the same table, to represent the home relationship set. CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 6

Or create a table for 1-many relationship Employee office 0..* home 0..1 0..1 manager 0..1 Department (code, ) Employee (,, office, dept) vs. Or...Create a newtable for a 1-many relationship set. Home-dept(, code) Department (code, ) Employee (,, office) Department code What are the tradeoffs between these two? Note: is the key for Home-dept CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 7

Employee office 0..* project-team 0..* role start-date end-date Project number start-date end-date budget When a many-many relationship set has attributes: Project-team (number,, role, start-date, end-date) Project (number,, start-date, end-date, budget) Employee (,, office) Put them in the table that represents the relationship. CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 8

Employee office 0..* home 0..1 0..1 manager 0..1 start-date end-date Department code When a 1-to-many relationship set has an attribute: add them to the table where the relationship is represented. Department (code,, manager, start-date, end-date) Employee (,, office, dept) or Manager (, code, start-date, end-date) CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 9

Participation Constraints in SQL We can require any table to be in a binary relationship using a foreign key which is required to be NOT NULL (but little else without resorting to CHECK constraints) CREATE TABLE Department ( code INTEGER, CHAR(20), manager CHAR(9) NOT NULL, DATE, start-date end-date DATE, PRIMARY KEY (d-code), FOREIGN KEY (manager-ssn) REFERENCES Employee, ON DELETE NO ACTION) CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 10

Translating Weak Entity Sets Weak entity sets and identifying relationship sets are translated into a single table. Must include key of strong entity set, as a foreign key. Key for this table is key of strong entity + partial key. When the owner entity is deleted, all owned weak entities must also be deleted. CREATE TABLE Insurance_Policy ( dep- CHAR(20), age INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (dep-, ssn), FOREIGN KEY (ssn) REFERENCES Employee, ON DELETE CASCADE) CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 11

Summary of Translation Steps: ER to Tables 1. Create table and choose key for each entity set; include single-valued attributes. 2. Create table for each weak entity set; include single-valued attributes. Include key of owner as a foreign key in the weak entity. Set key as foreign key of owner plus local, partial key. 3. For each 1:1 relationship set, add a foreign key to one of the entity sets involved in the relationship (a foreign key to the other entity in the relationship)*. 4. For each 1:N relationship set, add a foreign key to the entity set on the N-side of the relationship (to reference the entity set on the 1-side of the relationship)*. 5. For each M:N relationship set, create a new table. Include a foreign key for each participant entity set, in the relationship set. The key for the new table is the set of all such foreign keys. 6. For each multi-valued attribute, construct a separate table. Repeat the key for the entity in this new table. It will serve as both the key for this table as well as a foreign key to the original table for the entity. * Unless relationship set has attributes. If it does, create a new table for the relationship set. This algorithm from Elmasri/Navathe, p. 174. CS386/586 Introduction to Database Systems, Lois Delcambre 1999-2009 Slide 12