Lecture 8: The E/R Model I

Slides:



Advertisements
Similar presentations
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.
Advertisements

Information Systems Chapter 4 Relational Databases Modelling.
Lecture 9: Conceptual Database Design January 27 th, 2003.
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.
CS411 Database Systems Kazuhiro Minami 02: The Entity-Relationship Model.
Lecture 08: E/R Diagrams and Functional Dependencies.
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.
 Entity-relationship models (ERM) Entity-relationship models (ERM)  Simple E-R Diagram Simple E-R Diagram  Weak Entity Weak Entity  Strong Entity.
CSE 412/598 DATABASE MANAGEMENT COURSE NOTES 3. ENTITY-RELATIONSHIP CONCEPTUAL MODELING Department of Computer Science & Engineering Arizona State University.
COMP 430 Intro. to Database Systems Entity-Relationship Diagram Basics Slides use ideas from Chris Ré.
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.
Entity-Relationship Data Model
COP Introduction to Database Structures
Contents Design Process Modeling Constraints E-R Diagram Design Issues
Comp 1100 Entity-Relationship (ER) Model
Entity/Relationship Modelling
Lecture 5: Conceptual Database Design
Chapter 9 Domain Models.
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
Entity-Relationship Model
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:
Entity-Relationship Model
Tables and Their Characteristics
Chapter 7: Entity-Relationship Model
Database Management Systems (CS 564)
Lecture 4 Lecture 4: The E/R Model.
Conceptual Database Design
Outline of the ER Model By S.Saha
Chapter 2: Intro to Relational Model
Entity/Relationship Model
The Entity-Relationship Model
Entity-Relationship Model and Diagrams (continued)
Cse 344 May 14th – Entities.
Entity Relationship Diagrams
Data Modeling Concepts
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
MIS2502: Data Analytics Relational Data Modeling
Functional Dependencies
Session 2 Welcome: The fifth learning sequence
CMPT 354: Database System I
Lecture 9: The E/R Model II
Lectures 3: Introduction to SQL 2
Functional Dependencies
Chapter 7: Entity-Relationship Model
Lecture 10: The E/R Model III
Lecture 5: The Relational Data Model
Data Modeling Concepts
Functional Dependencies
MIS2502: Data Analytics Relational Data Modeling
Lecture 06: SQL Monday, October 11, 2004.
Chapter 7: Entity-Relationship Model
CS4433 Database Systems E-R Model.
Terminology Product Attribute names Name Price Category Manufacturer
Lectures 2: Introduction to SQL 1
MIS2502: Data Analytics Relational Data Modeling 2
Database Management system
Database Management system
Lecture 08: E/R Diagrams and Functional Dependencies
Entity-Relationship Data Model
Lecture 6: Functional Dependencies
Presentation transcript:

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

1. E/R Basics: Entities & Relations

What you will learn about in this section High-level motivation for the E/R model Entities Relations ACTIVITY: Crayon Time! Drawing E/R diagrams

Database Design Database design: Why do we need it? Agree on structure of the database before deciding on a particular implementation Consider issues such as: What entities to model How entities are related What constraints exist in the domain How to achieve good designs Several formalisms exist We discuss one flavor of E/R diagrams

Database Design Process 1. Requirements Analysis 2. Conceptual Design 3. Logical, Physical, Security, etc. Requirements analysis What is going to be stored? How is it going to be used? What are we going to do with the data? Who should access the data? Technical and non-technical people are involved

Database Design Process 1. Requirements Analysis 2. Conceptual Design 3. Logical, Physical, Security, etc. 2. Conceptual Design A high-level description of the database Sufficiently precise that technical people can understand it But, not so precise that non-technical people can’t participate This is where E/R fits in.

Database Design Process 1. Requirements Analysis 2. Conceptual Design 3. Logical, Physical, Security, etc. 3. More: Logical Database Design Physical Database Design Security Design

Database Design Process 1. Requirements Analysis 2. Conceptual Design 3. Logical, Physical, Security, etc. This process is iterated many times E/R Model & Diagrams used Makes Product name category price Company E/R is a visual syntax for DB design which is precise enough for technical points, but abstracted enough for non-technical people

Interlude: Impact of the ER model The E/R model is one of the most cited articles in Computer Science “The Entity-Relationship model – toward a unified view of data” Peter Chen, 1976 Used by companies big and small You’ll know it soon enough

Entities and Entity Sets Entities & entity sets are the primitive unit of the E/R model Entities are the individual objects, which are members of entity sets Ex: A specific person or product Entity sets are the classes or types of objects in our model Ex: Person, Product These are what is shown in E/R diagrams - as rectangles Entity sets represent the sets of all possible entities Product Person These represent entity sets

Entities and Entity Sets An entity set has attributes Represented by ovals attached to an entity set Shapes are important. Colors are not. Product name category price

Entities vs. Entity Sets Entities are not explicitly represented in E/R diagrams! Example: Entity Product name category price Name: Xbox Category: Total Multimedia System Price: $250 Name: My Little Pony Doll Category: Toy Price: $25 Entity Attribute Product Entity Set

Keys A key is a minimal set of attributes that uniquely identifies an entity. Denote elements of the primary key by underlining. Here, {name, category} is not a key (it is not minimal). If it were, what would it mean? Product name category price The E/R model forces us to designate a single primary key, though there may be multiple candidate keys

The R in E/R: Relationships A relationship is between two entities Company name Product name category price Makes

Product name category price Company stockprice name makes employs buys Person address name ssn

What is a Relationship? A mathematical definition: Let A, B be sets 1 A={1,2,3}, B={a,b,c,d} 1 2 3 a b c d A= B=

What is a Relationship? A mathematical definition: Let A, B be sets A={1,2,3}, B={a,b,c,d} A x B (the cross-product) is the set of all pairs (a,b) A  B = {(1,a), (1,b), (1,c), (1,d), (2,a), (2,b), (2,c), (2,d), (3,a), (3,b), (3,c), (3,d)} 1 2 3 a b c d A= B=

What is a Relationship? A mathematical definition: Let A, B be sets A={1,2,3}, B={a,b,c,d}, A x B (the cross-product) is the set of all pairs (a,b) A  B = {(1,a), (1,b), (1,c), (1,d), (2,a), (2,b), (2,c), (2,d), (3,a), (3,b), (3,c), (3,d)} We define a relationship to be a subset of A x B R = {(1,a), (2,c), (2,d), (3,b)} 1 2 3 a b c d A= B=

What is a Relationship? A mathematical definition: Let A, B be sets A x B (the cross-product) is the set of all pairs A relationship is a subset of A x B Makes is relationship- it is a subset of Product  Company: 1 2 3 a b c d A= B= makes Company Product

What is a Relationship? Makes Product name category price Company A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identified by P and C’s keys

What is a Relationship? Company Product name GizmoWorks GadgetCorp name category price Gizmo Electronics $9.99 GizmoLite $7.50 Gadget Toys $5.50 Makes Product name category price Company A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identified by P and C’s keys

What is a Relationship? Company C × Product P Company Product C.name P.name P.category P.price GizmoWorks Gizmo Electronics $9.99 GizmoLite $7.50 Gadget Toys $5.50 GadgetCorp name GizmoWorks GadgetCorp name category price Gizmo Electronics $9.99 GizmoLite $7.50 Gadget Toys $5.50 Makes Product name category price Company A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identified by P and C’s keys

What is a Relationship? Company C × Product P Company Product C.name P.name P.category P.price GizmoWorks Gizmo Electronics $9.99 GizmoLite $7.50 Gadget Toys $5.50 GadgetCorp name GizmoWorks GadgetCorp name category price Gizmo Electronics $9.99 GizmoLite $7.50 Gadget Toys $5.50 Makes Product name category price Company Makes C.name P.name GizmoWorks Gizmo GizmoLite GadgetCorp Gadget A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identified by P and C’s keys

What is a Relationship? There can only be one relationship for every unique combination of entities This also means that the relationship is uniquely determined by the keys of its entities Example: the “key” for Makes (to right) is {Product.name, Company.name} This follows from our mathematical definition of a relationship- it’s a SET! Makes Product name category price Company since KeyMakes = KeyProduct ∪ KeyCompany Why does this make sense?

Relationships and Attributes Relationships may have attributes as well. since Company name Product name category price Makes For example: “since” records when company started making a product Note: “since” is implicitly unique per pair here! Why? Note #2: Why not “how long”?

Decision: Relationship vs. Entity? Q: What does this say? A: A person can only buy a specific product once (on one date) Purchased Product name category price Person date Modeling something as a relationship makes it unique; what if not appropriate?

Decision: Relationship vs. Entity? What about this way? Now we can have multiple purchases per product, person pair! Product name category price Person date Purchase quantity PID# ProductOf BuyerOf We can always use a new entity instead of a relationship. For example, to permit multiple instances of each entity combination!

ACTIVITY: E/R Diagrams Part. I

Draw an E/R diagram for football Use the following simplified model of a football season (concepts to include are underlined): Team(s) play each other in Game(s). Each team has an ID and a name. Player(s) belong to Teams. Each player has an ID and a name. A Game is made up of Play(s). Each game has an ID, a location, and a date. A Play will result in a yardage gain/loss, and potentially a touchdown.