CS422 Principles of Database Systems Entity-Relationship Model

Slides:



Advertisements
Similar presentations
Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
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.
the Entity-Relationship (ER) Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Mapping ERM to relational database
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
SQL Structured Query Language Programming Course.
Initial Design of Entity Types for the COMPANY Database Schema Based on the requirements, we can identify four initial entity types in the COMPANY database:
CS 405G: Introduction to Database Systems Lecture 2 : Database Design I.
Entity-Relationship Model
Lecture 3 Book Chapter 3 (part 2 ) From ER to Relational.
CS422 Principles of Database Systems Convert ER Design to Relations Chengyu Sun California State University, Los Angeles.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles.
A short review on entity- relationship modelling.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
CS422 Principles of Database Systems From ER to Relations Chengyu Sun California State University, Los Angeles Adapted from Jeffrey Ullman’s lecture notes.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles Adapted from Jeffrey Ullman’s lecture.
Chapter 2: Entity-Relationship Model
Data Modeling Using the Entity- Relationship (ER) Model
COP Introduction to Database Structures
Contents Design Process Modeling Constraints E-R Diagram Design Issues
Comp 1100 Entity-Relationship (ER) Model
Session 2 Welcome: To the fourth learning sequence
Entity-Relationship Model
CS4222 Principles of Database System
Data Modeling Using the Entity- Relationship (ER) Model
Database Design Goal: specification of database schema Methodology:
Entity- Relationship (ER) Model
Entity-Relationship Model
ER model Ashima Wadhwa.
Entity-Relationship Model
CS320 Web and Internet Programming SQL and MySQL
COP4710 Database Systems E-R Model.
Information Systems Today: Managing in the Digital World
Entity-Relationship Model
Tables and Their Characteristics
Constraints in Entity-Relationship Models
CPSC-310 Database Systems
Entity-Relationship Modeling
CSCI-100 Introduction to Computing
The Entity-Relationship Model
Translation of ER-diagram into Relational Schema
CS 174: Server-Side Web Programming February 12 Class Meeting
CPSC-310 Database Systems
Lecture 4: Database Modeling (continued)
Overview of Database Systems
Entity Relationship Diagrams
LECTURE 34: Database Introduction
name category name price makes Company Product stockprice buys employs
The Entity-Relationship Model
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Overview of Database Systems
Conceptual Data Modeling Using Entities & Relationships
Lecture 9: The E/R Model II
ER Modeling Case Studies
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming SQL and MySQL
MIS2502: Data Analytics Relational Data Modeling
Lecture 06: SQL Monday, October 11, 2004.
Entity-Relationship Diagram (ERD)
Mapping an ERD to a Relational Database
CS4433 Database Systems E-R Model.
CS3220 Web and Internet Programming SQL and MySQL
Entity Relation Model Tingting Zhang.
Database Management system
Database Management system
LECTURE 33: Database Introduction
Overview of Database Systems
CS4222 Principles of Database System
Presentation transcript:

CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles

Designing Tables Is Not Easy Problem in Real World Tables in RDBM #42 Some Restaurant ? Date: Jul 09, 2008 Server: John Bill: 0060 Time: 03:07PM # of Guest: 2 Table: 42 1 Boiled Pork Wanton 1 Dumpling w/Crabmeat 1 Beef Noodle Soup 4.95 8.00 6.80 Subtotal: GST: 19.75 0.99 Total: 20.74 Open Time: Jul 09, 2008 02:57PM Printed by: Cashier

Entity-Relationship (ER) Model Problem ER Model Tables An object-oriented approach A visual representation of the design – ER Diagram Easily converted to relational model

Example: Problem Description Student id, name, address Department name Classes code, name, quarter, section number Class offerings and enrollment

Example: ER Diagram id name addr name Students Departments Entity Set Attribute Take Offer Relationship code quarter Classes name section

Entity Set and Attributes Entity Set is similar to class in an OO language Attributes are the properties of an entity set Similar to the class fields in an OO language Must have simple values like numbers or strings, i.e. cannot be collection or composite type

Keys A key is an attribute or a set of attributes that uniquely identify an entity in an entity set. Each entity set must have a key If there are multiple keys, choose one of them as the primary key

Types of Relationships Many-to-Many Many-to-One / One-to-Many One-to-One

Many-to-Many Relationship Each entity in E1 can be related to many entities in E2 Each entity in E2 can be related to many entities in E1 E1 E2

Many-to-One Relationship Each entity in E1 can be related to one entities in E2 Each entity in E2 can be related to many entities in E1 E1 E2

One-to-One Relationship Each entity in E1 can be related to one entities in E2 Each entity in E2 can be related to one entities in E1 E1 E2

Relationship Type Examples Students and classes?? Departments and classes?? Person and Favorite movie??

Relationship Types in ER Diagram Students Take Classes Departments Offer Classes Person Favorite Movies An arrow is used to indicate the “one” side

A Closer Look at “One” and “Many” 0 or 1 Exactly 1  Referential Integrity Many 0..N 1..N N..M (Example??)

Referential Integrity in ER Diagram Departments Offer Classes Person Favorite Movies An circular arrow is used to indicate “Exactly 1”

One vs. Exactly One Both lead to foreign key constraint in SQL One: foreign key + NULL Exactly one: foreign key + NOT NULL It’s usually not too important to distinguish the two in ER design

Data in a Relationship Entity Set Relationship Entity Set Joe Amy Tom Students Take Classes Joe Amy Tom … (Joe,CS122) (Amy,CS320) (Amy,CS422) (Tom,CS422) … CS122 CS320 CS422 … Relationship Set

Design Example: Bank Database Design a database for a bank to keep track of customers and accounts. Each account has id, and a balance; each customer has a name and address. A customer can own multiple accounts, and an account can be jointly owned by multiple customers.

ER Design (I) Step 1: identify entity sets, attributes, and relationships. Tips: Nouns tend to be entity sets or attributes Attribute: simple data that can be represented by a single value Entity Set: composite data Verbs tend to be relationships

ER Design (II) Step 2: determine relationship types Step 3: complete entity sets Identify/create keys Add additional attributes if necessary Some common problems: No keys Wrong relationship types Collection/composite attributes

Some Common Problems in ER Design id name addr name Students Departments Take Offer id Classes students code

Grades Store the grades the students received for their classes A grade is a single letter A, B, C, D, or F Students Take Classes ??

Relationship Attributes Sometimes it’s useful to attach an attribute to a relationship. Students Take Classes Grade

Other Relationship Attribute Examples Bars Sell Beers Price Users Rate Movies Rating Customers Order Products Date

From Relationship with Attributes to Entity Set … Some variations of ER model does not allow relationships to have attributes Students Take Classes Grade ??

… From Relationship with Attributes to Entity Set If something needs an attribute, it probably should be an entity set Students Enrollments Classes ?? ?? ?? ?? id Grade

Grades as an Entity Set Need to store more than just the letter ?? Students Take Classes ?? Grades description id letter grade_point

Multiway Relationship Students Take Classes Grades

Relationship Set of a Multiway Relationship (Joe) (Amy) (Tom) … Students Take Classes (CS122) (CS320) (CS422) … (Joe,CS122,A) (Amy,CS320,B) (Amy,CS422,A) (Tom,CS422,B) … (A) (A-) (B+) … Grades Relationship Set

“Arrows” in Multiway Relationships In multiway relationships, an arrow points to an entity set E means that if we select one entity from each of the other entity sets in the relationship, those entities are related to at most one entity in E.

Convert Multiway Relationship to Binary Relationship A multiway relationship can always be converted to binary relationships by replacing the multiway relationship with an entity set Students Enrollments Classes ?? ?? ?? ?? ?? ?? Grades

Compare the Ways to Model Grades A. Relationship attribute B. Entity set attribute C. Entity set in a multiway relationship D. Entity set in a binary relationship

Employees and Supervisors Each employee has a supervisor A supervisor is an employee id name Employees ??

Roles An entity set may appear in the same relationship more than once. Label the edges with names called Roles Supervise supervisor employee Employees

Players and Teams What’s the key for Players?? name number name Play-on Players Teams What’s the key for Players??

Weak Entity Set Entity set E is said to be weak if in order to identify entities of E uniquely, we need to follow one or more many-one relationships from E and include the key of the related entities from the connected entity sets.

Weak Entity Sets in ER Diagram name number name Play-on Players Teams The key of a weak entity set consists of its own key attributes and the key attributes of the supporting set

From Weak to Strong We can usually create unique IDs for entity sets

Subclass Super class must have all the key attributes Users id name isa Students cin Super class must have all the key attributes

When to Use (and When Not to Use) Subclass A: salaried employees and hourly employees B: administrator users and regular users C: pop songs and country songs D: beer and wine

Summary of ER Diagram Entity Set Relationship Attributes, key Weak entity set Relationship Many-to-Many, Many-to-One, One-to-One Attributes Multiway and binary relationships Subclass

Design Example 1: Restaurant #42 Some Restaurant Date: Jul 09, 2008 Server: John Bill: 0060 Time: 03:07PM # of Guest: 2 Table: 42 1 Boiled Pork Wanton 1 Dumpling w/Crabmeat 1 Beef Noodle Soup 4.95 8.00 6.80 Subtotal: GST: 19.75 0.99 Total: 20.74 Open Time: Jul 09, 2008 02:57PM Printed by: Cashier

Design Example 2: Folders and Files C:\ \WINNT \Document and Settings \Program Files \cysun \database material \web material file1 file2 file3 file4

Design Example 3: Price Changes id description price Products What if we want to model price changes?? $ Price of a product X time

Readings Database Systems: The Complete Book (2nd Ed) Chapter 4.1-4.4 Database Management Systems (3rd Ed) Chapter 2.1-2.6