CSIT5300: Advanced Database Systems

Similar documents
COMP Instructor: Dimitris Papadias WWW page:

Chapter 2: Entity-Relationship Model. Entity Sets. Entity Sets customer and loan. Attributes. Relationship Sets. A database can be modeled as:

Chapter 6: Entity-Relationship Model

Chapter 6: Entity-Relationship Model

Chapter 2: Entity-Relationship Model

Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to

Example: specific person, company, event, plant

Chapter 6: Entity-Relationship Model

Introduction to Database Design

6.1 RELATIONSHIP CONCEPTS

Introduction to Database Design

Lecture 14 of 42. E-R Diagrams, UML Notes: PS3 Notes, E-R Design. Thursday, 15 Feb 2007

The Entity-Relationship (ER) Model 2

Database Applications (15-415)

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

CSE 530A. ER Model. Washington University Fall 2013

Chapter 6: Entity-Relationship Model. E-R Diagrams

High-Level Database Models (ii)

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

High Level Database Models

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

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

Entity-Relationship Model

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

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

Intro to DB CHAPTER 6

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

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

Database Management Systems. Chapter 2 Part 2

Major components of ER diagram Practices

MIS Database Systems Entity-Relationship Model.

VARDHAMAN COLLEGE OF ENGINEERING Shamshabad , Hyderabad B.Tech. CSE IV Semester (VCE - R11) T P C 3+1* -- 4 (A1511) DATABASE MANAGEMENT SYSTEMS

The Entity-Relationship Model

The Entity-Relationship Model. Steps in Database Design

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

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

Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

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

2. E-R Model. Entity Sets Relationship Sets Attributes

Chapter 7: Entity-Relationship Model

The Entity-Relationship Model

The Entity-Relationship (ER) Model

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

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

COMP 244 DATABASE CONCEPTS & APPLICATIONS

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

CSIT5300: Advanced Database Systems

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

UNIT II A. ENTITY RELATIONSHIP MODEL

CSCC43H: Introduction to Databases

OVERVIEW OF DATABASE DEVELOPMENT

Chapter 7: Entity-Relationship Model. Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model

The Entity-Relationship Model. Overview of Database Design

CSC 261/461 Database Systems Lecture 8. Spring 2018

Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

Introduction to Database Design

Conceptual Design. The Entity-Relationship (ER) Model

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

The Entity-Relationship Model

Database Management Systems. Chapter 3 Part 2

CSC 261/461 Database Systems Lecture 8. Fall 2017

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

The Relational Model (ii)

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 7 Data Modeling with Entity Relationship Diagrams

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

The Relational Model. Chapter 3

The Relational Model 2. Week 3

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

More on the Chen Notation

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

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

Roadmap of This Lecture. Weak Entity Sets Extended E-R Features Reduction to Relation Schemas Database Design UML*

The En'ty Rela'onship Model

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

Database Applications (15-415)

Chapter Outline. Note 1. Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts


Conceptual Data Modeling

2. DatabaseDesign. Master I Software Engineering. Dr. Imed Bouchrika Dept of Mathematics & Computer Science University of Souk-Ahras

2004 John Mylopoulos. The Entity-Relationship Model John Mylopoulos. The Entity-Relationship Model John Mylopoulos

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

Represent entities and relations with diagrams

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

Database Design CENG 351

E-R Model. Hi! Here in this lecture we are going to discuss about the E-R Model.

Entity Relationship Data Model. Slides by: Shree Jaswal

Chapter 2 Conceptual Modeling. Objectives

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

Database Design & Deployment

Database Management System 6 ER Modeling...

CMSC 424 Database design Lecture 3: Entity-Relationship Model. Book: Chap. 1 and 6. Mihai Pop

Chapter 2 ENTITY RELATIONSHIP MODEL

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

MTAT Introduction to Databases

Database Management Systems LECTURE NOTES 2

CSC 261/461 Database Systems Lecture 10

XV. The Entity-Relationship Model

Transcription:

CSIT5300: Advanced Database Systems L01: Entity Relationship (ER) Model Dr. Kenneth LEUNG Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong SAR, China kwtleung@cse.ust.hk CSIT5300

Entity ER is a model for the logical level - it describes the structure of the database at a high abstraction level A database can be modeled as - a collection of entities - a relationship among entities An entity is an object that exists independently and is distinguishable from other objects - Examples: an employee, a company, a car, a student, a class etc. color, age, etc. are not entities kwtleung@cse.ust.hk CSIT5300 2

Entity Set An entity set is a set of entities of the same type Examples a set of employees, a set of departments also called entity types Entity Type: Employee A general specification Entity Set: e 1 e 2 e 3 The actual employees kwtleung@cse.ust.hk CSIT5300 3

Attribute An attribute is a property of an entity or a relationship Examples: name, address, weight, height are properties of a Person entity date of marriage is a property of a relationship Marriage Attribute types: Simple Composite Multivalued Derived Key kwtleung@cse.ust.hk CSIT5300 4

Types of Attributes Simple attribute: contains a single value EmpNo Employee Name Address kwtleung@cse.ust.hk CSIT5300 5

Types of Attributes Composite attribute: consists of several components (e.g., address) EmpNo Employee Address Name Street City Country kwtleung@cse.ust.hk CSIT5300 6

Types of Attributes Multivalued attribute: contains more than one value Employee Phone Email kwtleung@cse.ust.hk CSIT5300 7

Types of Attributes Derived attribute: computed from other attributes (e.g., age can be computed from the date of birth and the current date) Employee Age Date_of_birth kwtleung@cse.ust.hk CSIT5300 8

Types of Attributes Key attribute: uniquely identifies an entity ER Model Employee EmpNo Name Relational Model EmpNo Name... 123456 John Wong... 456789 Mary Cheung... 146777 John Wong... kwtleung@cse.ust.hk CSIT5300 9

More on Key Attributes An entity may have more than one key A minimal set of attributes that uniquely identifies an entity is called a candidate key Question: which are possible candidate keys for HKUST students? Only one candidate key is selected to be the primary key Question: which is the primary key for HKUST students? Sometimes artificial keys maybe created Example: assume that we want to store information about the current offering of CSIT5300. We can select a unique number (e.g., 1235) to serve as the key. Question: which are possible alternatives for this example, without introducing additional attributes? Composite Key: contains two or more attributes kwtleung@cse.ust.hk CSIT5300 10

Example E-R Diagram E-R diagram for entity customer kwtleung@cse.ust.hk CSIT5300 11

Relationship A relationship is an association among several entities The degree refers to the number of entity sets that participate in the relationship set Relationship sets that involve two entity sets are called binary (or of degree two) Relationship sets among more than two entity sets are called ternary kwtleung@cse.ust.hk CSIT5300 12

Example of (Binary) Relationship borrower is a relationship between customer and loan it means that a customer can be associated with one or more loans and vice versa kwtleung@cse.ust.hk CSIT5300 13

Attributes of Relationships depositor is a relationship between customer and accounts access-date is an attribute of depositor kwtleung@cse.ust.hk CSIT5300 14

Cardinality Constraints We express cardinality constraints by drawing either a directed line ( ), signifying one, or an undirected line ( ), signifying many, between the relationship set and the entity set One-to-one relationship A customer is associated with at most one loan via the relationship borrower A loan is associated with at most one customer via borrower kwtleung@cse.ust.hk CSIT5300 15

Cardinality Constraints One-to-many relationship a loan is associated with at most one customer via borrower a customer is associated with several (including 0) loans via borrower kwtleung@cse.ust.hk CSIT5300 16

Cardinality Constraints Many-to-one relationship a loan is associated with several (including 0) customers via borrower a customer is associated with at most one loan via borrower kwtleung@cse.ust.hk CSIT5300 17

Cardinality Constraints Many-to-many relationship A customer is associated with several (possibly 0) loans via borrower A loan is associated with several (possibly 0) customers via borrower kwtleung@cse.ust.hk CSIT5300 18

Participation of an Entity Set in a Relationship Set Total participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship set - E.g., participation of loan in borrower is total every loan must have at least a customer associated to it via borrower Partial participation: some entities may not participate in any relationship in the relationship set - E.g., participation of customer in borrower is partial some customers may not have any loans kwtleung@cse.ust.hk CSIT5300 19

Cardinality Limits The edge between loan and borrower has a cardinality limit of 1..1 the minimum and the maximum cardinality are both 1 each loan must have exactly one associated customer The limit 0..* on the edge from customer to borrower indicates that a customer can have zero or more loans. Observe that the relationship borrower is one to many from customer to loan the participation of loan in borrower is total Hence, cardinality limits can express cardinality and participation constraints kwtleung@cse.ust.hk CSIT5300 20

Roles Entity sets of a relationship need not be distinct The labels manager and worker are called roles; they specify how employee entities interact via the works-for relationship set Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to rectangles Role labels are optional, and are used to clarify semantics of the relationship kwtleung@cse.ust.hk CSIT5300 21

Keys for Relationship Sets The combination of primary keys of the participating entity sets forms a super key of a relationship set (customer-id, account-number) is the super key of depositor This means that a pair of entities can have at most one relationship in a particular relationship set Problem: if we wish to track all access dates to each account by each customer, we cannot assume a relationship for each access Solution: use a multivalued attribute for access dates Must consider the mapping cardinality of the relationship set when deciding the candidate keys kwtleung@cse.ust.hk CSIT5300 22

Ternary Relationship Sets Example: Suppose that employees of a bank have jobs (responsibilities) at multiple branches, with different jobs at different branches Then there is a ternary relationship set between entity sets employee, job and branch kwtleung@cse.ust.hk CSIT5300 23

Binary vs. Ternary Relationships Some relationships that appear to be ternary may be better represented using binary relationships Example: A ternary relationship parents, relating a child to his/her father and mother, is best replaced by two binary relationships, father and mother Using two binary relationships allows partial information (e.g. only mother being known) But there are some relationships that are naturally ternary Example: works-on kwtleung@cse.ust.hk CSIT5300 24

Converting Ternary Relationships to Binary Form In general, any non-binary relationship can be represented using binary relationships by creating an artificial entity set Procedure (degree 3) Replace R between entity sets A, B and C by an entity set E, and three relationship sets: R A relating E and A, R B relating E and B and R C relating E and C Create a special identifying attribute for E Add any attributes of R to E For each relationship (a i, b i, c i ) in R, (i) create a new entity e i in the entity set E, (ii) add (e i, a i ) to R A, (iii) add (e i, b i ) to R B, (iv) add (e i, c i ) to R C kwtleung@cse.ust.hk CSIT5300 25

Converting Ternary Relationships to Binary Form Example R a 1 b 1 c 1 a 2 b 1 c 1 a 2 b 1 c 2 a 2 b 2 c 2 E e 1 e 2 e 3 e 4 R a R b R c a 1 e 1 b 1 e 1 c 1 e 1 a 2 e 2 a 2 e 3 a 2 e 4 b 1 e 2 b 1 e 3 b 2 e 4 c 1 e 2 c 2 e 3 c 2 e 4 kwtleung@cse.ust.hk CSIT5300 26

Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set The existence of a weak entity set depends on the existence of an identifying entity set it must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the weak entity set this relationship is called identifying relationship The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes the entities in the weak entity set that depend on a particular strong entity set The primary key of a weak entity set is formed by the primary key of the (strong) identifying entity set the weak entity set s discriminator kwtleung@cse.ust.hk CSIT5300 27

Weak Entity Sets A weak entity set is depicted by a double rectangle An identifying relationship is depicted by a double diamond We underline the discriminator of a weak entity set with a dashed line Example: discriminator of payment: payment-number Primary key for payment: (loan-number, payment-number) kwtleung@cse.ust.hk CSIT5300 28

Weak Entity Sets Another example: A child may not be old enough to have a HKID number Even if he/she has a HKID number, the company may not be interested in keeping it in the database. EmpNo Name Employee Emp_Dep Dependent Age kwtleung@cse.ust.hk CSIT5300 29

ISA ( is a ) Hierarchies If we declare A ISA B, every A entity is also considered to be a B entity As in C++ (and other program languages), attributes are inherited Reasons for using ISA: To add descriptive attributes specific to a subclass To identify entities that participate in a relationship kwtleung@cse.ust.hk CSIT5300 30

ISA ( is a ) Hierarchies Overlap constraints: Can Joe be both an Hourly_Emps and a Contract_Emps entity? Covering constraints: Does every Employees entity also have to be an Hourly_Emps or a Contract_Emps entity? ssn name lot Employees hourly_wages hours_worked ISA contractid Hourly_Emps Contract_Emps kwtleung@cse.ust.hk CSIT5300 31

Summary of Symbols kwtleung@cse.ust.hk CSIT5300 32

ER Design Decisions Entity vs. Attribute Example For each employee we want to store the office number, location of the office (e.g., Building A, Floor 6), and telephone. Several employees share the same office Office as attribute Employee_id Office_number Office_location Name Employee Office_phone Employee_id Office as entity Office_number Office_location Name Employee Office Office_phone kwtleung@cse.ust.hk CSIT5300 33

ER Design Decisions Entity vs. Relationship Example Can you see some differences? E.g., can you have accounts without a customer? A possible guideline A relationship set describes an action that occurs between entities Account as an entity Customer Account Branch Account as relationship Account Customer Branch kwtleung@cse.ust.hk CSIT5300 34

ER Design Decisions Entity vs. Ternary Relationship Example: We want to record the period that an employ works for some department Differences below? ssn name lot from to did dname budget Employees Works_In1 Departments ssn name lot did dname budget Employees Works_In2 Departments from Duration to kwtleung@cse.ust.hk CSIT5300 35

ER Design Decisions Strong vs. Weak Entity Example: an account must be associated with exactly one branch two different branches are allowed to have accounts with the same number Number Branch_id Account Branch kwtleung@cse.ust.hk CSIT5300 36