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

Post on 21-Jan-2016

226 views 0 download

Tags:

transcript

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

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.

AttributesAttributes are properties used to describe an

entity. for example an EMPLOYEE entity may have a

Name, SSN, Address, Sex, BirthOfDate.

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'.

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

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

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.

INSERT FIGURE 3.4

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.

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}.

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.

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.

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.

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.

INSERT FIGURE 3.6

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.

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.

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).

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).

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.

INSERT FIGURE 3.7

INSERT FIGURE 3.8

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.

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.

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.

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.

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.

INSERT FIGURE 3.9

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

Binary relationship

Ternary relationship

INSERT FIGURE 3.10

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.

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.

INSERT FIGURE 3.11

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.

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.

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

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

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.

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

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.

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.

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

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)

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.

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.

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

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

ER DIAGRAM FOR A BANK DATABASE

ER diagram for book publisher