57
Data Modeling Using the Entity- Relationship (ER) Data Model

Data Modeling Using the Entity-Relationship (ER) Data Model

Embed Size (px)

Citation preview

Page 1: Data Modeling Using the Entity-Relationship (ER) Data Model

Data Modeling Using the Entity-Relationship (ER) Data Model

Page 2: Data Modeling Using the Entity-Relationship (ER) Data Model

ER Model Concepts Entities and AttributesEntity Types, Value Sets, and Key AttributesRelationships and Relationship TypesStructural Constraints and RolesWeak Entity Types

Page 3: Data Modeling Using the Entity-Relationship (ER) Data Model

EntitiesAn entity is a “thing” in the real world with an

independent existence (conceptual or physical). Entities are specific objects or things in the

mini-world that are represented in the database; for example the EMPLOYEE ,

DEPARTMENT, PROJECT, CAR, HOUSE etc.

Page 4: Data Modeling Using the Entity-Relationship (ER) Data Model
Page 5: Data Modeling Using the Entity-Relationship (ER) Data Model

AttributesAttributes are properties used to describe an

entity. for example an EMPLOYEE entity may have a

Name, SSN, Address, Sex, BirthOfDate.

Page 6: Data Modeling Using the Entity-Relationship (ER) Data Model

Particular EntitiesA particular entity (specific entity) will have

a value for each of its attributes; for example a specific employee entity may have

Name='John Smith', SSN='123456789', Address='731 Fondren, Houston, TX',Sex='M', BirthOfDate='09-JAN-55'.

Page 7: Data Modeling Using the Entity-Relationship (ER) Data Model

Types of Attributes Simple versus CompositeSingle-value versus Multi-valuedStored versus DerivedComplex Attributes

Page 8: Data Modeling Using the Entity-Relationship (ER) Data Model

Simple Attributes:Each entity has a single atomic value for the attribute; for example SSN or Age.

Page 9: Data Modeling Using the Entity-Relationship (ER) Data Model

Composite Attributes: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.

Page 10: Data Modeling Using the Entity-Relationship (ER) Data Model

INSERT FIGURE 3.4

Page 11: Data Modeling Using the Entity-Relationship (ER) Data Model

Single-valued AttributesMost attributes have a single value for a particular

entity; such attributes are called single-valued.For example, Age is a single-valued attribute

of person.

Page 12: Data Modeling Using the Entity-Relationship (ER) Data Model

Multi-valued Attributes: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}.

Page 13: Data Modeling Using the Entity-Relationship (ER) Data Model

Stored VS. Derived Attributes

In some cases two (or more) attribute values are related.

Some attribute values can be derived from related entities.

For example,The value of Age can be determined from the

current date and the value of that person’s BirthOfDate.

Page 14: Data Modeling Using the Entity-Relationship (ER) Data Model

Null ValuesIn some case a particular entity may not have an applicable

value for an attributes.For such situations, a special value called NULL is created.

Page 15: Data Modeling Using the Entity-Relationship (ER) Data Model

Entity TypesEntities with the same basic attributes are grouped or

typed into an entity type. For example, the EMPLOYEE entity type and

the PROJECT entity type.

Page 16: Data Modeling Using the Entity-Relationship (ER) Data Model

Entity SetsThe collection of all entities of a particular entity type

in the database at any point in time is called an entities set.

The entities set is usually referred to using the same name as the entity type.

Page 17: Data Modeling Using the Entity-Relationship (ER) Data Model

INSERT FIGURE 3.6

Page 18: Data Modeling Using the Entity-Relationship (ER) Data Model

An Entity TypeAn entity type describes the schema or intension for a

set of entities that share the same structure.The collection of entities of a particular entity type are

grouped into an entity set, which is also called the extension of the entity type.

Page 19: Data Modeling Using the Entity-Relationship (ER) Data Model

Key Attributes of an Entities TypeAn 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.

Page 20: Data Modeling Using the Entity-Relationship (ER) Data Model

Key Attributes of an Entities TypeA key attribute may be composite. For example, VehicleRegistrationNumber is a key of

the CAR entity type with components (Number, State).

Page 21: Data Modeling Using the Entity-Relationship (ER) Data Model

Key Attributes of an Entities TypeAn entity type may have more than one key. For example, the CAR entity type may have two keys:

VehicleIdentificationNumber and VehicleRegistrationNumber(Number,

State).

Page 22: Data Modeling Using the Entity-Relationship (ER) Data Model

Value Sets (Domains) of AttributesEach simple attributes of an entity type is associated

with a value set (or domain of values), which specifies the set of values that may be assigned to that attribute for each individual entity.

Page 23: Data Modeling Using the Entity-Relationship (ER) Data Model

INSERT FIGURE 3.7

Page 24: Data Modeling Using the Entity-Relationship (ER) Data Model

INSERT FIGURE 3.8

Page 25: Data Modeling Using the Entity-Relationship (ER) Data Model

RelationshipsA relationship relates two or more distinct entities

with a specific meaning; For example,

EMPLOYEE John Smith works on the Product X PROJECT or

EMPLOYEE Franklin manages the Research DEPARTMENT.

Page 26: Data Modeling Using the Entity-Relationship (ER) Data Model

Relationship TypesRelationships 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.

Page 27: Data Modeling Using the Entity-Relationship (ER) Data Model

Relationship TypesA relationship type R among n entity types E1, E2,…,En

defines a set of associations – or a relationship set – among entities from these Entity types.

Page 28: Data Modeling Using the Entity-Relationship (ER) Data Model

Degree of a Relationship TypeThe degree of a relationship type is the number of

participating entity types. Both MANAGES and WORKS_ON are binary

relationships.

Page 29: Data Modeling Using the Entity-Relationship (ER) Data Model

Relationship typesMore 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 participate.

Page 30: Data Modeling Using the Entity-Relationship (ER) Data Model

INSERT FIGURE 3.9

Page 31: Data Modeling Using the Entity-Relationship (ER) Data Model

Relationships of Higher DegreeRelationship types of degree 2 are called binaryRelationship types of degree 3 are called ternary and of

degree n are called n-aryIn general, an n-ary relationship is not equivalent to n

binary relationships

Page 32: Data Modeling Using the Entity-Relationship (ER) Data Model

Binary relationship

Page 33: Data Modeling Using the Entity-Relationship (ER) Data Model

Ternary relationship

Page 34: Data Modeling Using the Entity-Relationship (ER) Data Model

INSERT FIGURE 3.10

Page 35: Data Modeling Using the Entity-Relationship (ER) Data Model

Roles NamesEach entity type that participates in a relationship type

plays a particular role in the relationship.The role name signifies the role that a participating

entity from the entity type plays in each relationship instance, and helps to explain what the relationship means.

Page 36: Data Modeling Using the Entity-Relationship (ER) Data Model

Roles NameFor example,

in the WORK_FOR relationship type, EMPLOYEE plays the role of employee or worker and DEPARTMENT plays the role of department or

employer.

Page 37: Data Modeling Using the Entity-Relationship (ER) Data Model
Page 38: Data Modeling Using the Entity-Relationship (ER) Data Model

INSERT FIGURE 3.11

Page 39: Data Modeling Using the Entity-Relationship (ER) Data Model

Structural constraints on relationships:Cardinality ratio (of a binary relationship):

1:1, 1:N, N:1, or M:N.Participation constraint (on each participating

entity type): total (called existence dependency ) or partial.

Page 40: Data Modeling Using the Entity-Relationship (ER) Data Model

Cardinality ratios for Binary Relationships.The cardinality ratio for a binary

relationship specifies the number of relationship instances that an entity can participate in.

The possible cardinality ratios for binary relationship types are 1:1, 1:N, N:1, M:N.

Page 41: Data Modeling Using the Entity-Relationship (ER) Data Model

Mapping Cardinalities

One to one

One to many

Note: Some elements in A and B may not be mapped to any elements in the other set

Page 42: Data Modeling Using the Entity-Relationship (ER) Data Model

Mapping Cardinalities

Many to one Many to many

Note: Some elements in A and B may not be mapped to any elements in the other set

Page 43: Data Modeling Using the Entity-Relationship (ER) Data Model

Participation ConstraintsThe participation constraint specifies whether the

existence of an entity depends on its being related to another entity via the relationship type.

There are two types of participation constraints 1) total

2) partial.

Page 44: Data Modeling Using the Entity-Relationship (ER) Data Model

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 a customer associated to it via borrower

Partial participation: some entities may not participate in any relationship in the relationship set Example: participation of customer in borrower is partial

Page 45: Data Modeling Using the Entity-Relationship (ER) Data Model

Relationships Attributes A 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.

Page 46: Data Modeling Using the Entity-Relationship (ER) Data Model

Weak Entity TypesAn entity type that does not have a key attribute.A weak entity type must participate in an identifying

relationship type with an owner or identifying entity type.

Page 47: Data Modeling Using the Entity-Relationship (ER) Data Model

Weak Entity TypesEntities are identified by the combination of :

A partial key of the weak entity typeThe particular entity they are related to

in the identifying entity type

Page 48: Data Modeling Using the Entity-Relationship (ER) Data Model

We depict a weak entity set by double rectangles.We underline the discriminator of a weak entity set with a

dashed line.payment number – discriminator of the payment entity set Primary key for payment – (loan_number,

payment_number)

Page 49: Data Modeling Using the Entity-Relationship (ER) Data Model

Example:Suppose that a DEPENDENT entity is

identified by the dependent's first name and the specific EMPLOYEE that the dependent is related to.

DEPENDENT is a weak entity type with EMPLOYEE as its identifying entity type via the identifying relationship type DEPENDENT_OF.

Page 50: Data Modeling Using the Entity-Relationship (ER) Data Model
Page 51: Data Modeling Using the Entity-Relationship (ER) Data Model

Alternative (min, max) notation for relationship structural constraints:Specified on each participation of an entity type E in

a relationship type R.Specifies that each entity e in E participates in at least

min and at most max relationship instances in R.Default (no constraint): min=0, max=n.Must have min<max, min>0, max>1.Derived from the mini-world constraints.

Page 52: Data Modeling Using the Entity-Relationship (ER) Data Model

Examples (a):A department has exactly one manager and an

employee can manage at most one department.Specify (1,1) for participation of

DEPARTMENT in MANAGESSpecify (0,1) for participation of

EMPLOYEE in MANAGES

Page 53: Data Modeling Using the Entity-Relationship (ER) Data Model

Examples (b):An employee can work for exactly one

department but a department can have any number of employees.Specify (1,1) for participation of

EMPLOYEE in WORKS_FORSpecify (0,n) for participation of

DEPARTMENT in WORKS_FOR

Page 54: Data Modeling Using the Entity-Relationship (ER) Data Model
Page 55: Data Modeling Using the Entity-Relationship (ER) Data Model

ER DIAGRAM FOR A BANK DATABASE

Page 56: Data Modeling Using the Entity-Relationship (ER) Data Model
Page 57: Data Modeling Using the Entity-Relationship (ER) Data Model

ER diagram for book publisher