Lecture 9: The E/R Model II

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

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.
Information Systems Chapter 4 Relational Databases Modelling.
1 Lecture 04 Entity/Relationship Modelling. 2 Outline E/R model (Chapter 5) From E/R diagrams to relational schemas (Chapter 5) Constraints in SQL (Chapter.
1 Lecture 3: Database Modeling (continued) April 5, 2002.
Lecture 9: Conceptual Database Design January 27 th, 2003.
Multiplicity in E/R Diagrams
Database Design April 3, Projects, More Details Goal: build a DB application. (almost) anything goes. Groups of 3-4. End of week 2: groups formed.
Lecture 2: Entity-Relationship Modeling
Entity / Relationship Diagrams Objects entities Classes entity sets Attributes are like in ODL. Relationships: like in ODL except - not associated with.
CS411 Database Systems Kazuhiro Minami 02: The Entity-Relationship Model.
Lecture 2: E/R Diagrams and the Relational Model Thursday, January 4, 2001.
Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the.
1 Introduction to Database Systems CSE 444 Lecture 07 E/R Diagrams October 10, 2007.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
COMP 430 Intro. to Database Systems Entity-Relationship Diagram Basics Slides use ideas from Chris Ré.
COMP 430 Intro. to Database Systems ER Design Considerations Slides use ideas from Chris Ré.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles.
ER Diagrams and Relational Model CS 174a (Winter 2015)
Lecture 4: The E/R Model Lecture 4 Today’s Lecture 1.E/R Basics: Entities & Relations ACTIVITY: Crayon time! 2.E/R Design considerations ACTIVITY: Crayon.
CS422 Principles of Database Systems Entity-Relationship Model
COP Introduction to Database Structures
CS4222 Principles of Database System
Database Management Systems
Lecture 5: Conceptual Database Design
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
Relational Database Design by ER- and EER-to- Relational Mapping
Entity Relationship Model
COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL
COP4710 Database Systems E-R Model.
Database Design Oct. 3, 2001.
Database Design Why do we need it? Consider issues such as:
MIS2502: Data Analytics Relational Data Modeling
Entity-Relationship Model
Lecture 4 Lecture 4: The E/R Model.
02: ER Model Ch 4.1 – 4.4 Optionally, begin with Ch 2.1.
Conceptual Database Design
Modeling Your Data Chapter 2 cs542
Translation of ER-diagram into Relational Schema
Entity-Relationship Model and Diagrams (continued)
Cse 344 May 14th – Entities.
Module 8 – Database Design Using the E-R Model
Cse 344 May 11th – Entities.
Lecture 06 Data Modeling: E/R Diagrams
Functional Dependencies and Relational Schema Design
Lecture 09: Functional Dependencies, Database Design
name category name price makes Company Product stockprice buys employs
The Entity-Relationship Model
Functional Dependencies
Relationships as Primary & Foreign Keys
CMPT 354: Database System I
Faloutsos - Pavlo C. Faloutsos - A. Pavlo Lecture#2: E-R diagrams
Lecture 8: The E/R Model I
From data needs to ER Model to relational DB Schema
Lectures 3: Introduction to SQL 2
Functional Dependencies
Lecture 10: The E/R Model III
Chengyu Sun California State University, Los Angeles
Relational Database Design by ER- and EER-to- Relational Mapping
Functional Dependencies
Lecture 06: SQL Monday, October 11, 2004.
DBMS ER-Relational Mapping
Day 2 - Basic Database Backbone
CS4433 Database Systems E-R Model.
Lectures 2: Introduction to SQL 1
MIS2502: Data Analytics Relational Data Modeling 2
Lecture 08: E/R Diagrams and Functional Dependencies
The Entity-Relationship Model
Lecture 6: Functional Dependencies
Chapter 6b: Database Design Using the E-R Model
Presentation transcript:

Lecture 9: The E/R Model II Lecture and activity contents are based on what Prof Chris Ré used in his CS 145 in the fall 2016 term with permission.

2. E/R Design Considerations

What you will learn about in this section Relationships cont’d: multiplicity, multi-way Design considerations Conversion to SQL ACTIVITY: Crayon Time! Drawing E/R diagrams Pt. II

Multiplicity of E/R Relationships 1 2 3 a b c d One-to-one: Indicated using arrows 1 2 3 a b c d Many-to-one: X -> Y means there exists a function mapping from X to Y (recall the definition of a function) 1 2 3 a b c d One-to-many: 1 2 3 a b c d Many-to-many:

What does this say? name category name price makes Company Product stockprice What does this say? buys employs Person name ssn address

Multi-way Relationships How do we model a purchase relationship between buyers, products and stores? Purchase Product Person Store NB: Can still model as a mathematical set (how?)

Arrows in Multiway Relationships Q: What does the arrow mean ? Purchase Product Person Store

Arrows in Multiway Relationships Q: What does the arrow mean ? Product Purchase Store Person

Arrows in Multiway Relationships Q: How do we say that every person shops in at most one store ? Product Person Store Purchase A: Cannot. This is the best approximation. (Why only approximation ?)

Converting Multi-way Relationships to Binary Purchase Person Store Product StoreOf ProductOf BuyerOf date From what we had on previous slide to this - what did we do?

Converting Multi-way Relationships to New Entity + Binary Relationships Side note: What arrows should be added here? Are these correct? ProductOf Product date StoreOf Purchase Store BuyerOf Person

Decision: Multi-way or New Entity + Binary? Multi-way Relationship Entity + Binary Purchase Person Store Product StoreOf ProductOf BuyerOf date Purchase Product Person Store Should we use a single multi-way relationship or a new entity with binary relations?

Decision: Multi-way or New Entity + Binary? (A) Multi-way Relationship (B) Entity + Binary Purchase Person Store Product StoreOf ProductOf BuyerOf date Purchase Product Person Store Multiple purchases per (product, store, person) combo possible here! Covered earlier: (B) is useful if we want to have multiple instances of the “relationship” per entity combination

Decision: Multi-way or New Entity + Binary? (A) Multi-way Relationship (B) Entity + Binary Purchase Person Store Product StoreOf ProductOf BuyerOf date Purchase Product Person Store We can add more-fine-grained constraints here! (B) is also useful when we want to add details (constraints or attributes) to the relationship “A person who shops in only one store” “How long a person has been shopping at a store”

Decision: Multi-way or New Entity + Binary? (A) Multi-way Relationship (B) Entity + Binary Purchase Person Store Product StoreOf ProductOf BuyerOf date Purchase Product Person Store (A) is useful when a relationship really is between multiple entities - Ex: A three-party legal contract

3. Design Principles What’s wrong with these examples? Purchase Product Person President Person Country

Design Principles: What’s Wrong? date Product Purchase Store personAddr personName

Design Principles: What’s Wrong? date Dates Product Purchase Store Person

Examples: Entity vs. Attribute Should address (A) be an attribute? Or (B) be an entity? Address Street Addr ZIP Employee AddrOf Employee Addr 1 Addr 2

Examples: Entity vs. Attribute Should address (A) be an attribute? How do we handle employees with multiple addresses here? How do we handle addresses where internal structure of the address (e.g. zip code, state) is useful? Employee Addr 1 Addr 2

Examples: Entity vs. Attribute Or (B) be an entity? Should address (A) be an attribute? Address Street Addr ZIP Employee AddrOf Employee Addr 1 Addr 2 In general, when we want to record several values, we choose new entity

From E/R Diagrams to Relational Schema Key concept: Both Entity sets and Relationships become relations (tables in RDBMS)

From E/R Diagrams to Relational Schema Product price category name An entity set becomes a relation (multiset of tuples / table) Each tuple is one entity Each tuple is composed of the entity’s attributes, and has the same primary key Product name price category Gizmo1 99.99 Camera Gizmo2 19.99 Edible

From E/R Diagrams to Relational Schema price category name Product CREATE TABLE Product( name CHAR(50) PRIMARY KEY, price DOUBLE, category VARCHAR(30) ) Product name price category Gizmo1 99.99 Camera Gizmo2 19.99 Edible

From E/R Diagrams to Relational Schema Purchased Product name category price Person firstname date lastname A relation between entity sets A1, …, AN also becomes a multiset of tuples / a table Each row/tuple is one relation, i.e. one unique combination of entities (a1,…,aN) Each row/tuple is composed of the union of the entity sets’ keys has the entities’ primary keys as foreign keys has the union of the entity sets’ keys as primary key Purchased name firstname lastname date Gizmo1 Bob Joe 01/01/15 Gizmo2 01/03/15 JoeBob Smith 01/05/15

From E/R Diagrams to Relational Schema Purchased Product name category price Person firstname date lastname CREATE TABLE Purchased( name CHAR(50), firstname CHAR(50), lastname CHAR(50), date DATE, PRIMARY KEY (name, firstname, lastname), FOREIGN KEY (name) REFERENCES Product, FOREIGN KEY (firstname, lastname) REFERENCES Person ) Purchased name firstname lastname date Gizmo1 Bob Joe 01/01/15 Gizmo2 01/03/15 JoeBob Smith 01/05/15

From E/R Diagram to Relational Schema How do we represent this as a relational schema? date firstname lastname name category price Product Purchased Person name address Store

ACTIVITY: E/R Diagrams Part II

Add arrows to 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