CSC 261/461 Database Systems Lecture 8. Fall 2017

Similar documents
CSC 261/461 Database Systems Lecture 8. Spring 2018

CSC 261/461 Database Systems Lecture 10

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

Lecture 5. Lecture 5: The E/R Model

Lecture 4. Lecture 4: The E/R Model

CSC 261/461 Database Systems Lecture 6. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

Introduction to Database Design

High-Level Database Models (ii)

Introduction to Database Design

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

MIS Database Systems Entity-Relationship Model.

CSC 261/461 Database Systems Lecture 7

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

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

3. Advanced E/R Concepts

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

The Entity-Relationship Model

High Level Database Models

Conceptual Design. The Entity-Relationship (ER) Model

OVERVIEW OF DATABASE DEVELOPMENT

The Relational Model 2. Week 3

CSE 530A. ER Model. Washington University Fall 2013

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

Introduction to Databases

The Entity-Relationship Model. Overview of Database Design

CSIT5300: Advanced Database Systems

L11: ER modeling 4. CS3200 Database design (sp18 s2) 2/15/2018

Database Management Systems. Chapter 3 Part 2

Database Applications (15-415)

Introduction to Database Systems CSE 414

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

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

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

3. Advanced E/R Concepts

COMP Instructor: Dimitris Papadias WWW page:

The Entity-Relationship Model. Steps in Database Design

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

The Entity-Relationship (ER) Model

The Entity-Relationship Model

ER Model. CSC 343 Winter 2018 MICHAEL LIUT

The Entity-Relationship (ER) Model 2

The Relational Model (ii)

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

Review The Big Picture

Entity-Relationship Diagrams

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

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

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

Conceptual Design. The Entity-Relationship (ER) Model

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

The Entity-Relationship Model

Translating an ER Diagram to a Relational Schema

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

Database Applications (15-415)

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

ER to Relational Mapping. ER Model: Overview

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

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

Introduction to Data Management CSE 344

CSE 344 MAY 14 TH ENTITIES

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

Database Systems CSE 414

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

Database Systems CSE 414

Introduction to Database Design

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

Database Management Systems. Chapter 2 Part 2

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

COMP 244 DATABASE CONCEPTS & APPLICATIONS

Entity/Relationship Modelling

More on the Chen Notation

Introduction to Data Management CSE 344

Database Systems. Course Administration

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

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

The Relational Model. Chapter 3

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

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

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

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

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

Introduction to Data Management CSE 344

CIS 330: Applied Database Systems

Database Design CENG 351

Database Design & Deployment

Introduction to Data Management CSE 344

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

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

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

Database Design Process Entity / Relationship Diagrams

Database Systems ( 資料庫系統 )

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

Conceptual Design with ER Model

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

ENTITY-RELATIONSHIP MODEL. CS 564- Spring 2018

Database Applications (15-415)

Agent 7 which languages? skills?

A l Ain University Of Science and Technology

CSE 344 AUGUST 1 ST ENTITIES

Introduction to Database Systems CSE 414. Lecture 19: E/R Diagrams

Transcription:

CSC 261/461 Database Systems Lecture 8 Fall 2017

Announcement Project 2 is out. Not a group project! CSC 261, Spring 2017, UR

Agenda More about ER model ER model to Relation (Table) CSC 261, Spring 2017, UR

Chen Notation vs Crow s Foot Notation Textbook inverts the (min, max) notations. We are following that for consistency 1 N (1,N) (1,1) http://www.vertabelo.com/blog/technical-articles/chen-erd-notation http://www.vertabelo.com/blog/technical-articles/crow-s-foot-notation CSC 261, Spring 2017, UR https://creately.com/ https://www.draw.io/

Special Symbols Used CSC 261, Spring 2017, UR

Strong and Weak Entities A weak entity is an entity whose instances cannot exist in the database without the existence of an instance of another entity Any entity that is not weak entity is called a strong entity Instances of a strong entity can exist in the database independently The weak entity s identifier is a combination of the identifier of the owner entity and the partial key of the weak entity. CSC 261, Spring 2017, UR

In E/R Diagrams number Players Playson Teams Double diamond for supporting many-one relationship. Double rectangle for the weak entity set. 7

Example: Weak Entity Set is almost a key for football players, but there might be two with the same. number is certainly not a key, since players on two teams could have the same number. But number, together with the team related to the player should be unique. 8

Partial vs Total Participation An entity set may participate in a relation either totally or partially. Total participation means that every entity in the set is involved in the relationship depicted as a double line. Partial participation means that not all entities in the set are involved in the relationship, e.g., not every professor guides a student depicted by a single line. CSC 261, Spring 2017, UR

Weak Entity, Total Participation and Partial Key CSC 261, Spring 2017, UR

HAS-A Relationships The relationships in the previous slides are called HAS-A relationships The term is used because each entity instance has a relationship to a second entity instance An employee has a locker A locker has an employee There are also IS-A relationships CSC 261, Spring 2017, UR

Modeling Subclasses Some objects in a class may be special, i.e. worthy of their own class Define a new class? But what if we want to maintain connection to current class? Better: define a subclass Ex: Products Software products Educational products We can define subclasses in E/R! 12

Modeling Subclasses price Product isa Child subclasses contain all the attributes of all of their parent classes plus the new attributes shown attached to them in the E/R diagram Software Product Educational Product platforms agegroup 13

Understanding Subclasses Think in terms of records; ex: Product price SoftwareProduct price platforms EducationalProduct price Product isa Child subclasses contain all the attributes of all of their parent classes plus the new attributes shown attached to them in the E/R diagram price agegroup Software Product Educational Product platforms agegroup 14

Think like tables Product price category Gizmo 99 gadget Camera 49 photo price Toy 39 gadget Product Sw.Product platforms isa Ed.Product Gizmo unix Software Product Educational Product agegroup platforms agegroup Gizmo todler Toy retired 15

Summary Summary Identifying Relationship CSC 261, Spring 2017, UR

ACTIVITIES 17

DRAW AN E/R DIAGRAM FOR FOOTBALL Use the following simplified model of a football season (concepts to include are underlined): Teams play each other in Games. Each pair of teams can play each other multiple times Players belong to Teams A Game is made up of Plays that result in a yardage gain/loss, and potentially a touchdown A Play will contain either a Pass from one player to another, or a Run by one player 18

Note that various ER diagrams could work, not just the following one! ACTIVITY

Note two copies of the Teams entity here! Team ID date location Teams PlayingAway PlayingHome Games Teams play each other in Games. Each pair of teams can play each other multiple times

Team ID Player ID date location Teams MemberOf PlayingAway Players PlayingHome Games Players belong to Teams (assume no trades / changes)

Team ID Player ID date location Teams MemberOf PlayingAway Players PlayingHome Games OccurIn Plays Play ID Yardage Diff Touchdown A Game is made up of Plays that result in a yardage gain/loss, and potentially a touchdown

Team ID date location Player ID Teams MemberOf PlayingAway Players Games PlayingHome Participation Type OccurIn Plays ParticipateIn Play ID A Play will contain either a Pass from one player to another, or a Run by one player Yardage Diff Touchdown

Note that various ER diagrams could work, not just the following one! ACTIVITY 2

ENHANCE YOUR E/R DIAGRAM! Also make sure to add (new concepts underlined): A player can only belong to one team, a play can only be in one game, a pass/run..? Players can achieve a Personal Record linked to a specific Game and Play Players have a weight which changes in on vs. off-season 25

Team ID Player ID date location Teams MemberOf PlayingAway Players PlayingHome Games Participation Type Plays OccurIn ParticipateIn A player can only belong to one team, a play can only be in one game, a pass/run..? Play ID Yardage Diff Touchdown

Team ID date location Player ID Teams MemberOf PlayingAway Players Games PlayingHome Participation Type ParticipateIn OccurIn Plays PRIn Play ID Yardage Diff Touchdown Players can achieve a Personal Record linked to a specific Game and Play

Team ID Player ID date location Teams MemberOf PlayingAway WeightOf Weight Players ParticipateIn Participation Type PlayingHome OccurIn Games Players might have different weights at different times Weight Plays Player ID Time Period PRIn Play ID Yardage Diff Touchdown Note: point here is that different players might have different numbers of training / weight phaseshence should represent as new entity!

Note that various ER diagrams could work, not just the following one! ACTIVITY 3

ADD IN: SUBCLASSES, CONSTRAINTS, AND WEAK ENTITY SETS Concepts to include / model: Teams belong to cities- model as weak entity sets Players are either on Offense or Defense, and are of types (QB, RB, WR, TE, K) All passes are to exactly one player; all runs include a player Make sure you have designated keys for all our concepts! 30

Team Name Teams LocatedIn Cities Name Teams belong to cities- model as weak entity sets

Team Name Player ID MemberOf Players LocatedIn PlaysPosition Position Teams Type Cities String isa OffensePosition DefensePosition OffensivePosType DefensivePosType Name Players are either on Offense or Defense, and are of types (QB, RB, WR, TE, etc.)

Design Theory (ER model to Relations)

Entity Sets to Tables ssn lot ssn lot 123-22-3333 Alex 23 234-44-6666 Bob 44 567-88-9787 John 12 Employees CREATE TABLE Employees ( ssn char(11), varchar(30), lot Integer, PRIMARY KEY (ssn)) CSC 261, Spring 2017, UR

Relationship Sets (without Constraints) to Tables since d ssn lot did budget Employees Works_In Departments address Locations capacity CSC 261, Spring 2017, UR

Relationship Sets (without Constraints) to Tables CREATE TABLE Works_in( ssn char(11), did integer (30), address varchar(30), since date, PRIMARY KEY (ssn, did, address), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (address) REFERENCES Locations, FOREIGN KEY (did) REFERENCES Departments, ) CSC 261, Spring 2017, UR

Relationship Sets (without Constraints) to Tables ssn supervisor lot Employees Reports_To subordinate CREATE TABLE Reports_To( supervisor_ssn char(11), subordinate_ssn char(11), PRIMARY KEY (supervisor_ssn, subordinate_ssn), FOREIGN KEY (supervisor_ssn ) REFERENCES Employees(ssn), FOREIGN KEY (subordinate_ssn ) REFERENCES Employees(ssn) ) CSC 261, Spring 2017, UR

Relationship Sets (with key Constraints) to Tables since d ssn lot did budget Employees Manages Departments CREATE TABLE Manages( ssn char(11), did integer (30), since date, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments, ) CSC 261, Spring 2017, UR

Better way of doing it since d ssn lot did budget Employees Manages Departments CREATE TABLE Dept_Mgr( did integer (30), d varchar(30), budget float(30), ssn char(11), since date, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, ) CSC 261, Spring 2017, UR

Relationship Sets (with Participation Constraints) to Tables since d ssn lot did budget Employees Manages Departments CREATE TABLE Dept_Mgr( did integer (30), d varchar(30), budget float(30), ssn char(11), since date, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees ON DELETE NO ACTION ) CSC 261, Spring 2017, UR

Translating Weak Entity Sets cost ssn lot p age Employees Policy Dependents CREATE TABLE Dept_Policy( p varchar(30), age integer, cost float, ssn char(11), PRIMARY KEY (p, ssn), FOREIGN KEY (ssn) REFERENCES Employees ON DELETE CASCADE ) CSC 261, Spring 2017, UR

Translating Class Hierarchies ssn lot Hours_worked Employees Contract_id Hourly_wages isa Hourly_Emps Contract Emps CSC 261, Spring 2017, UR

Two options 1. We can map each of the entity sets Employees, Hourly_Emps, and Contract_Emps to a distinct relation. 2. We can create just two relations, corresponding to Hourly_Emps and Contract_Emps Both have their pros and cons Redundancy Performance CSC 261, Spring 2017, UR

E/R Summary E/R diagrams are a visual syntax that allows technical and non-technical people to talk For conceptual design Basic constructs: entity, relationship, and attributes A good design is faithful to the constraints of the application, but not overzealous 44

Scenario One customer can have at max 2 loans. One loan can be given to multiple customers. What it really means: One customer can have (0,2) loans One loan can be given to (1,n) customer This is a many to many scenario CSC 261, Spring 2017, UR

Crow s foot Notation Chen Notation CSC 261, Spring 2017, UR

Acknowledgement Some of the slides in this presentation are taken from the slides provided by the authors. Many of these slides are taken from cs145 course offered by Stanford University. Thanks to YouTube, especially to Dr. Daniel Soper for his useful videos. CSC 261, Spring 2017, UR