Docsity

Data Modeling Using the Entity Relationship Model | CS 6400, Study notes of Computer Science

Partial preview of the text

Download Data Modeling Using the Entity Relationship Model | CS 6400 and more Study notes Computer Science in PDF only on Docsity!

Chapter 3

Data Modeling Using the

Entity-Relationship (ER) Model

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Chapter Outline

z Example Database Application (COMPANY)

z ER Model Concepts

  • Entities and Attributes
  • Entity Types, Value Sets, and Key Attributes
  • Relationships and Relationship Types
  • Weak Entity Types
  • Roles and Attributes in Relationship Types

z ER Diagrams - Notation

z ER Diagram for COMPANY Schema

z Alternative Notations – UML class diagrams, others

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Example COMPANY

Database

z Requirements of the Company (oversimplified for

illustrative purposes)

  • The company is organized into DEPARTMENTs. Each department has a name, number and an employee who manages the department. We keep track of the start date of the department manager.
  • Each department controls a number of PROJECTs_._ Each project has a name, number and is located at a single location.

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Types of Attributes (1)

z Simple

  • Each entity has a single atomic value for the attribute. For example, SSN or Sex.

z Composite

  • The attribute may be composed of several components. For example, Address (Apt#, House#, Street, City, State, ZipCode, Country) or Name (FirstName, MiddleName, LastName). Composition may form a hierarchy where some components are themselves composite.

z Multi-valued

  • An entity may have multiple values for that attribute. For example, Color of a CAR or PreviousDegrees of a STUDENT. Denoted as {Color} or {PreviousDegrees}.

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Types of Attributes (2)

z In general, composite and multi-valued attributes may be

nested arbitrarily to any number of levels although this is rare. For example, PreviousDegrees of a STUDENT is a composite multi-valued attribute denoted by {PreviousDegrees (College, Year, Degree, Field)}.

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Entity Types and Key Attributes

z Entities with the same basic attributes are grouped or typed into an entity type. For example, the EMPLOYEE entity type or the PROJECT entity type. z An attribute of an entity type for which each entity must have a unique value is called a key attribute of the entity type. For example, SSN of EMPLOYEE. z A key attribute may be composite. For example, VehicleTagNumber is a key of the CAR entity type with components (Number, State). z An entity type may have more than one key. For example, the CAR entity type may have two keys:

  • VehicleIdentificationNumber (popularly called VIN) and
  • VehicleTagNumber (Number, State), also known as license_plate number.

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

ENTITY SET corresponding to the

ENTITY TYPE CAR

car 1 ((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red, black)) car (^2) ((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue)) car (^3) ((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue))

CAR Registration(RegistrationNumber, State), VehicleID, Make, Model, Year, (Color)

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Relationships and Relationship

Types (1)

z A relationship relates two or more distinct entities with a specific meaning. For example, EMPLOYEE John Smith works on the ProductX PROJECT or EMPLOYEE Franklin Wong manages the Research DEPARTMENT. z Relationships of the same type are grouped or typed into a relationship type. For example, the WORKS_ON relationship type in which EMPLOYEEs and PROJECTs participate, or the MANAGES relationship type in which EMPLOYEEs and DEPARTMENTs participate. z The degree of a relationship type is the number of participating entity types. Both MANAGES and WORKS_ON are binary relationships.

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Example relationship instances of the WORKS_FOR relationship between EMPLOYEE and DEPARTMENT

e 1 z e 2 z

e 3 z e 4 z e 5 z e 6 z e 7 z

EMPLOYEE

r (^1)

r (^2)

r (^3)

r (^4)

r (^5)

r (^6)

r (^7)

WORKS_FOR

z d^1

z d^2

z d^3

DEPARTMENT

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Example relationship instances of the WORKS_ON relationship between EMPLOYEE and PROJECT

e 1 z e 2 z e 3 z e 4 z

e 5 z e 6 z e 7 z

r (^1)

r (^2)

r (^3)

r (^4)

r (^5)

r (^6)

r (^7)

z p^1

z p^2

z p^3

r (^8)

r (^9)

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Relationships and Relationship

Types (2)

z More than one relationship type can exist with the same

participating entity types. For example, MANAGES and WORKS_FOR are distinct relationships between EMPLOYEE and DEPARTMENT, but with different meanings and different relationship instances.

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Weak Entity Type is: DEPENDENT

Identifying Relationship is: DEPENDENTS_OF

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Constraints on Relationships

z Constraints on Relationship Types

  • ( Also known as ratio constraints )
  • Maximum Cardinality z One-to-one (1:1) z One-to-many (1:N) or Many-to-one (N:1) z Many-to-many
  • Minimum Cardinality (also called participation constraint or existence dependency constraints) z zero (optional participation, not existence-dependent) z one or more (mandatory, existence-dependent)

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Many-to-one (N:1) RELATIONSHIP

e 1 z e 2 z

e 3 z e 4 z e 5 z e 6 z

e 7 z

EMPLOYEE

r (^1)

r (^2)

r (^3)

r (^4)

r (^5)

r (^6)

r (^7)

WORKS_FOR

z d^1

z d^2

z d^3

DEPARTMENT

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Many-to-many (M:N) RELATIONSHIP

e 1 z e 2 z e 3 z e 4 z

e 5 z e 6 z e 7 z

r (^1)

r (^2)

r (^3)

r (^4)

r (^5)

r (^6)

r (^7)

z p^1

z p^2

z p^3

r (^8)

r (^9)

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Recursive Relationship Type is: SUPERVISION

(participation role names are shown)

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Attributes of Relationship types

zA relationship type can have attributes; for

example, HoursPerWeek of WORKS_ON; its value for each relationship instance describes the number of hours per week that an

EMPLOYEE works on a PROJECT.

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Attribute of a Relationship Type is:

Hours of WORKS_ON

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Structural Constraints –

one way to express semantics

of relationships

Structural constraints on relationships:

z Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or M:N SHOWN BY PLACING APPROPRIATE NUMBER ON THE LINK.

z Participation constraint (on each participating entity type): total (called existence dependency ) or partial.

SHOWN BY DOUBLE LINING THE LINK

NOTE: These are easy to specify for Binary Relationship Types.

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

COMPANY ER Schema Diagram

using (min, max) notation

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Relationships of Higher Degree

z Relationship types of degree 2 are called binary

z Relationship types of degree 3 are called ternary and of

degree n are called n-ary

z In general, an n-ary relationship is not equivalent to n

binary relationships

z Higher-order relationships discussed further in Chapter 4

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Data Modeling Tools

A number of popular tools that cover conceptual

modeling and mapping into relational schema

design. Examples: ERWin, S- Designer

(Enterprise Application Suite), ER- Studio, etc.

POSITIVES: serves as documentation of

application requirements, easy user interface - mostly graphics editor support

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Problems with Current

Modeling Tools

z DIAGRAMMING

  • Poor conceptual meaningful notation.
  • To avoid the problem of layout algorithms and aesthetics of diagrams, they prefer boxes and lines and do nothing more than represent (primary-foreign key) relationships among resulting tables.(a few exceptions)

z METHODOLGY

  • lack of built-in methodology support.
  • poor tradeoff analysis or user-driven design preferences.
  • poor design verification and suggestions for improvement.

Chapter 3- Copyright © 2004 Pearson Education, Inc.

Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

PROBLEM with ER notation

THE ENTITY RELATIONSHIP MODEL IN ITS ORIGINAL FORM DID NOT SUPPORT THE SPECIALIZATION/ GENERALIZATION ABSTRACTIONS

Chapter 3- Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition

Extended Entity-Relationship

(EER) Model

z Incorporates Set-subset relationships

z Incorporates Specialization/Generalization Hierarchies

NEXT CHAPTER ILLUSTRATES HOW THE ER

MODEL CAN BE EXTENDED WITH

  • Set-subset relationships and

Specialization/Generalization Hierarchies and how to

display them in EER diagrams