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

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
ER Modeling Case Studies
Overview of Database Systems CPSC 315 – Programming Studio Spring 2009 Team Project 1, Lecture 1.
Ch5: ER Diagrams - Part 1 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Mapping an ERD to a Relational Database To map an ERD to a relational database, five rules are defined to govern how tables are constructed. 1)Rule for.
Databases Revision.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Chapter Five Data Modeling with the Entity-Relationship Model.
The Entity-Relationship Data Model
Information Resources Management January 30, 2001.
1 Lecture 3: Database Modeling (continued) April 5, 2002.
Chapter 4 Entity-Relationship modeling Transparencies © Pearson Education Limited 1995, 2005.
Database Management COP4540, SCS, FIU Database Modeling Using the Entity-Relationship Model (Chapter 3)
CS411 Database Systems Kazuhiro Minami
CS 405G Introduction to Database Systems
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas.
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
Data Modeling Using the Entity-Relationship Model
Ch5: ER Diagrams - Part 2 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
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.
1. 2 Data Modeling 3 Process of creating a logical representation of the structure of the database The most important task in database development E-R.
Entities and Attributes
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Chapter 5 Entity–Relationship Modeling
1 ER Modeling BUAD/American University Entity Relationship (ER) Modeling.
Concepts and Terminology Introduction to Database.
SQL Structured Query Language Programming Course.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
CS 564 Database Management Systems: Design and Implementation
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 7 Database Design and The E–R Model. 2 Goals n Facilitate DB design and represent the overall logical structure of the DB. n Definition Entities.
© Pearson Education Limited, Chapter 7 Entity-Relationship modeling Transparencies.
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.
Database Management Systems MIT Lesson 02 – Database Design (Entity Relationship Diagram) By S. Sabraz Nawaz.
 Entity-relationship models (ERM) Entity-relationship models (ERM)  Simple E-R Diagram Simple E-R Diagram  Weak Entity Weak Entity  Strong Entity.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Entity-Relationship Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
Databases Illuminated Chapter 3 The Entity Relationship Model.
1 The Entity- Relationship Model Instructor: Mohamed Eltabakh
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
INTRODUCTION TO DATA MODELING CS 260 Database Systems.
Data Modeling Using the Entity- Relationship (ER) Model.
1 The Entity- Relationship Model Instructor: Mohamed Eltabakh Part-2.
The Entity-Relationship Model, P. I R. Nakatsu. Data Modeling A data model is the relatively simple representation, usually graphic, of the structure.
CSE 412/598 DATABASE MANAGEMENT COURSE NOTES 3. ENTITY-RELATIONSHIP CONCEPTUAL MODELING Department of Computer Science & Engineering Arizona State University.
CS422 Principles of Database Systems Convert ER Design to Relations Chengyu Sun California State University, Los Angeles.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
A short revision on entity- relationship modelling.
Modeling: Entity-Relationship Diagrams
A short review on entity- relationship modelling.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
Database Designsemester Slide 1 Database Design Lecture 7 Entity-relationship modeling Text , 7.1.
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.
Data Modeling Using the Entity- Relationship (ER) Model
CS422 Principles of Database Systems Entity-Relationship Model
COP Introduction to Database Structures
Entity-Relationship Model
Entity-Relationship Modeling
Conceptual Data Modeling Using Entities & Relationships
Chengyu Sun California State University, Los Angeles
CS4433 Database Systems E-R Model.
Entity Relation Model Tingting Zhang.
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 WorldTables in RDBM ? Some Restaurant #42 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 Subtotal: GST: Total: Open Time: Jul 09, :57PM Printed by: Cashier

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

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

Example: ER Diagram Classes name Departments name Students name addr TakeOffer Entity Set Attribute Relationship id codequarter 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 E 1 can be related to many entities in E 2 Each entity in E 2 can be related to many entities in E 1 E1E1 E2E2

Many-to-One Relationship Each entity in E 1 can be related to one entities in E 2 Each entity in E 2 can be related to many entities in E 1 E1E1 E2E2

One-to-One Relationship Each entity in E 1 can be related to one entities in E 2 Each entity in E 2 can be related to one entities in E 1 E1E1 E2E2

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

Relationship Types in ER Diagram ClassesStudents Take ClassesDepartments Offer MoviesPerson Favorite An arrow is used to indicate the “one” side

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

Referential Integrity in ER Diagram ClassesDepartments Offer MoviesPerson Favorite 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

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 Classes code Departments name Students name addr TakeOffer id students

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

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

Other Relationship Attribute Examples BeersBars Sell MoviesUsers Rate Price ProductsCustomers Order Rating Date

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

… From Relationship with Attributes to Entity Set If something needs an attribute, it probably should be an entity set ClassesStudentsEnrollments Gradeid ??

Grades as an Entity Set Need to store more than just the letter ClassesStudents Take Grades letteridgrade_point ?? description

Multiway Relationship ClassesStudents Take Grades Why there is an arrow pointing to Grades ??

“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 Grades ClassesStudentsEnrollments ??

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 Employees nameid ??

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

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

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 The key of a weak entity set consists of its own key attributes and the key attributes of the supporting set PlayersTeams Play-on name number

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

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

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 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 Some Restaurant #42 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 Subtotal: GST: Total: Open Time: Jul 09, :57PM Printed by: Cashier

Design Example 2: Folders and Files C:\ \WINNT\Document and Settings\Program Files \cysun \database material\web material file1file2file3file4

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