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

Similar documents
High-Level Database Models (ii)

Database Management Systems. Chapter 3 Part 2

The Entity-Relationship Model

High Level Database Models

The Relational Model (ii)

The Entity-Relationship Model. Overview of Database Design

The Relational Model 2. Week 3

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

The Relational Model. Chapter 3

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

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

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

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

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

Database Applications (15-415)

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

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

OVERVIEW OF DATABASE DEVELOPMENT

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

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

Database Design & Deployment

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

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

The Entity-Relationship Model

Introduction to Database Design

Database Systems ( 資料庫系統 )

The Entity-Relationship Model

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

Introduction to Database Design

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

ER to Relational Mapping. ER Model: Overview

Introduction to Database Design. Dr. Kanda Runapongsa Dept of Computer Engineering Khon Kaen University

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

The Entity-Relationship Model. Overview of Database Design. ER Model Basics. (Ramakrishnan&Gehrke, Chapter 2)

The Entity-Relationship (ER) Model

CSC 261/461 Database Systems Lecture 10

CIS 330: Web-driven Web Applications. Lecture 2: Introduction to ER Modeling

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

CIS 330: Applied Database Systems

Database Systems. Course Administration

Conceptual Design. The Entity-Relationship (ER) Model

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

Database Management Systems. Chapter 2 Part 2

Introduction to Databases

The Entity-Relationship (ER) Model 2

CSE 530A. ER Model. Washington University Fall 2013

Introduction to Database Design

COMP Instructor: Dimitris Papadias WWW page:

Database Applications (15-415)

CS/INFO 330 Entity-Relationship Modeling. Announcements. Goals of This Lecture. Mirek Riedewald

Conceptual Design. The Entity-Relationship (ER) Model

Database Design. ER Model. Overview. Introduction to Database Design. UVic C SC 370. Database design can be divided in six major steps:

CSIT5300: Advanced Database Systems

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

Entity-Relationship Diagrams

Overview. Introduction to Database Design. ER Model. Database Design

Database Design CENG 351

Introduction to Data Management. Lecture #3 (Conceptual DB Design) Instructor: Chen Li

Translating an ER Diagram to a Relational Schema

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

Database Management Systems. Session 2. Instructor: Vinnie Costa

CSC 261/461 Database Systems Lecture 8. Spring 2018

ER Model Overview. The Entity-Relationship Model. Database Design Process. ER Model Basics

The Entity-Relationship Model. Steps in Database Design

MIS Database Systems Entity-Relationship Model.

Integrity constraints, relationships. CS634 Lecture 2

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

Database Applications (15-415)

CSC 261/461 Database Systems Lecture 8. Fall 2017

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

SYLLABUS ADMIN DATABASE SYSTEMS I WEEK 2 THE ENTITY-RELATIONSHIP MODEL. Assignment #2 changed. A2Q1 moved to A3Q1

Database Management Systems. Syllabus. Instructor: Vinnie Costa

VARDHAMAN COLLEGE OF ENGINEERING Shamshabad , Hyderabad B.Tech. CSE IV Semester (VCE - R11) T P C 3+1* -- 4 (A1511) DATABASE MANAGEMENT SYSTEMS

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

COMP 244. ER-Diagram Notations. Entity-Relationship Diagrams DATABASE CONCEPTS & APPLICATIONS. Database Concepts & Applications 1.

The Relational Model

Database Applications (15-415)

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

COMP 244 DATABASE CONCEPTS & APPLICATIONS

Introduction to Data Management. Lecture #3 (E-R Design, Cont d.)

ER Model. CSC 343 Winter 2018 MICHAEL LIUT

The Relational Model

The Relational Model

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

DATABASE MANAGEMENT SYSTEMS

SQL DDL. CS3 Database Systems Weeks 4-5 SQL DDL Database design. Key Constraints. Inclusion Constraints

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

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

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

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

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

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

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

RDBMS (Relational Database Management Systems)

ER to Relational Mapping

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

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

Topic 5: Mapping of EER Diagrams to Relations

2. DatabaseDesign. Master I Software Engineering. Dr. Imed Bouchrika Dept of Mathematics & Computer Science University of Souk-Ahras

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

Transcription:

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

Logical DB Design: ER to Relational Translate Entity sets to tables: ssn name Employees lot CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot INTEGER, PRIMARY KEY (ssn))

Translate Relationship Sets to Tables name since dname ssn lot did budget Employees Works_In Departments

Translate Relationship Sets to Tables Attributes of relation include: Keys for each participating entity set All descriptive attributes. CREATE TABLE Works_In( ssn CHAR(11), did INTEGER, since DATE) name since dname ssn lot did budget Employees Works_In Departments

Translate Relationship Sets to Tables Foreign Keys: Keys: Keys for each participating entity set (?) This set of attributes forms superkey for relation (?) CREATE TABLE Works_In( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) name since dname ssn lot did budget Employees Works_In Departments

Key Constraints 1-to-1 1-to Many Many-to-1 Many-to-Many Translation to relational model?

Review: Key Constraint Each dept has at most one manager, according to key constraint Each department appears only once in relationship name ssn lot Employees since Manages dname did budget Departments Translation to relational model? 1-to Many

Translate Key Constraint : Approach I. Separate tables for Employees and Departments Note that did is key now! TABLE Dept( ) TABLE Employee ( ) CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments)

Translate Key Constraint: Approach II. Combine Manages and Departments into one relation. Each department has a unique manager TABLE Employee ( ) CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11), since DATE, ) name since dname ssn lot did budget Employees Manages Departments

Translate Key Constraint: Approach II. TABLE Employee ( ) CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11), since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees) name since dname ssn lot did budget Employees Manages Departments

Participation + Key Constraint. Every department must have a manager! Every did value in Departments table must appear in a row of the Manages table (with a non-null ssn value!) name since dname ssn lot did budget Employees Manages Departments

Participation Constraints in SQL Approach I. every did value in Department appears in a tuple of Managers corresponding tuple must have a non-null ssn values TABLE Dept( ) TABLE Employee ( ) CREATE TABLE Manages( ssn CHAR(11) NOT NULL, did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments, Does this capture with not-null work?

Participation Constraints in SQL Approach I. every did value in Department appears in a tuple of Works_In the corresponding tuple must have a non-null ssn values TABLE Dept_mgr( ) TABLE Employee ( ) CREATE TABLE Manages( ssn CHAR(11) NOT NULL, did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments, CHECK ( (SELECT Count(*) FROM Manages) = (SELECT Count(*) FROM Dept) ) Must utilize check constraints!

Participation Constraints in SQL Approach II. - capture participation constraints involving one entity set in a binary relationship using combined table. TABLE Employee ( ) CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, SEMANTICS??? ) Does this non-null approach now work?

Participation Constraints in SQL Approach II. - capture participation constraints involving one entity set in a binary relationship using combined table. TABLE Employee ( ) CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, SEMANTICS??? ) What should happen if manager-employee is deleted?

Participation Constraints in SQL Approach II. - use the on action propagation constraint! CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE NO ACTION)

More on Participation Constraints What about other cases of must have constraint? ssn name lot since did dname budget Employees Manages Departments Works_In since What if we want to capture participation for manyto-many relationships? Anwer: We need to use CHECK constraints.

Review: Weak Entities A weak entity can be identified uniquely only by considering primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-tomany relationship set (1 owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. name ssn lot cost pname age Employees Policy Dependents

Translating Weak Entity Sets Weak entity set and identifying relationship set are translated into a single table. CREATE TABLE Dep_Policy ( pname CHAR(20), age INTEGER, cost REAL, ssn CHAR(11) NOT NULL, --- (?), PRIMARY KEY (pname, ssn), --- (?) FOREIGN KEY (ssn) REFERENCES Employees, WHAT SEMANTICS HERE??? )

Translating Weak Entity Sets When the owner entity is deleted, all owned weak entities must also be deleted CREATE TABLE Dep_Policy ( pname CHAR(20), age INTEGER, cost REAL, ssn CHAR(11), PRIMARY KEY (pname, ssn), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE)

Review: ISA Hierarchies Attributes are inherited ssn name lot Employees hourly_wages hours_worked ISA ISA contractid Hourly_Emps Contract_Emps

Translating ISA Hierarchies What are possible alternatives of mapping IS-A to the relational model?

Translating ISA Hierarchies Alternative : Three Relations Employees ( ssn, name, lot) Hourly_Emps (ssn, hourly_wages, hours_worked); Contract_Emps (ssn, contractid); Alternative: Two Relations Hourly_Emps (ssn, name, lot, hourly_wages, hours_worked) Contract_Emps (ssn, name, lot, contractid) Alternative: One Relation Emps (ssn, name, lot, hourly_wages, hours_worked,contractid)

Pros/Cons : Translating ISA Hierarchies Pros/cons for three relations: + Queries involving all employees easy - Queries involving just Hourly_Emps may require accessing multiple tables Pros/Cons for two relations: - If all employees must be of the subentity type ( total ), then no need to create a table for the super-entity type - This design has each employee in one of these two subclasses. - Avoid joins for subtable queries - Disadvantage that keys are stored redundantly. Pros/Cons for one relation: - Looses isa semantics - May have many many nulls

ISA Hierarchy Translation? ssn name lot Employees hourly_wages hours_worked ISA contractid Hourly_Emps Contract_Emps 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)

Relations Corresponding to Aggregation To represe t aggregatio, create a tab e ith: primary key of the aggregated re atio ship primary key of the associated e tity set a y descriptive attributes

Mapping Aggregation Manages bet ee aggregatio re atio ship works-on a d e tity manager:

Mapping Aggregation create tab e manages(employee-id, branch-name, title, manager-name)

Summary ER Modeling : graphical design view Relational Model: A tabular representation of data. Rules to translate ER to relational model exist Later : More design optimizations can be applied, after initial relational design has been derived.