53
Entity Relationship Modeling Chapter 11

Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Embed Size (px)

Citation preview

Page 1: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Entity Relationship ModelingChapter 11

Page 2: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Objectives

•ER Model•Entity type•Relationship type•Attribute•Cardinality and modality•Symbols•Examples

Page 3: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

ER Model• It is a semantic data model that is used for the

graphical representation of the conceptual database design.

• An ER Model is a detailed, logical representation of the data for an organization or for a business area.

• It is expressed in terms of entities in the business environment, the relationships (or associations) among those entities, and the attributes of both the entities and their relationships.

• An ER model is normally expressed as an entity-relationship diagram which is graphical representation of an ER model.

Page 4: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Concepts of the ER Model

•Entity types•Relationship types•Attributes

Page 5: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Entity Types

•Entity type▫Group of objects with same properties, identified

by enterprise as having an independent existence.

•Entity occurrence▫Uniquely identifiable object of an entity type.

Page 6: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Example of Entity Type

Page 7: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Relationship Types

•Relationship type▫Set of meaningful associations among entity types.

•Relationship occurrence▫Uniquely identifiable association, which includes

one occurrence from each participating entity type.

Page 8: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Attributes

•Attribute▫Property of an entity or a relationship type.

•Attribute Domain▫Set of allowable values for one or more attributes.

Page 9: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Symbols

Page 10: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Example

Page 11: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Attribute Types

•Simple Attribute▫Attribute composed of a single component with an

independent existence.▫E.g. salary attribute of Staff entity.

•Composite Attribute▫Attribute composed of multiple components, each

with an independent existence.▫E.g. address attribute of Branch entity can be

subdivided into city, street and postcode attributes.

Page 12: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Composite Attribute Representation

Page 13: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Attribute Types (Contd.)•Single-valued Attribute

▫Attribute that holds a single value for each occurrence of an entity type.

▫E.g. each occurrence of the Branch entity type has a single value for the branchNo attribute.

•Multi-valued Attribute▫Attribute that holds multiple values for each

occurrence of an entity type. ▫Each occurrence of the Branch entity type can have

multiple values for telNo attribute.

Page 14: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Attribute Types (Contd.)•Derived Attribute

▫Attribute that represents a value that is derivable from value of a related attribute, or set of attributes, not necessarily in the same entity type.

▫E.g. age attribute of Staff entity type can be calculated from dateOfBirth attribute.

Page 15: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Symbols (Attribute Types)

Page 16: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Entity Type•Strong Entity Type

▫Entity type that is not existence-dependent on some other entity type.

▫Instances of a strong entity type always have a unique characteristic (called identifier)

▫E.g. Student, Employee, Course etc

•Weak Entity Type▫Entity type that is existence-dependent on some

other entity type.

Page 17: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Entity types

Page 18: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Entity Type• Employee is a strong entity type with identifier

employee_id (denoted by underline). • Dependent is a weak entity type, indicated by

double-lined rectangle.• The relationship between a weak entity type

and its owner is called an identifying relationship. (indicated by double lined diamond symbol)

• The attribute dependent_name serves as partial identifier (indicated by double undderline).

• During a later design stage, dependent_name will be combined with employee_id to form a full identifier for Dependent.

Page 19: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Cardinality and Modality• Cardinality is the specification of the number

of occurrences of one [object] that can be related to the number of occurrences of another [object]. Cardinality is usually expressed as simply 'one' or 'many.'

• Cardinality defines “the maximum number of objects that can participate in a relationship”.

• The modality of a relationship is 0 if there is no explicit need for the relationship to occur or the relationship is optional. The modality is 1 if an occurrence ofthe relationship is mandatory.

Page 20: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Symbols

Page 21: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Example

Page 22: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Degree of relationship•The number of entity types that

participate in a relationship.•3 typesUnary: Relationship between instances of

a single entity typeBinary: Relationship between instances of

two entity typesTernary: A simultaneous relationship

among instances of three entity types

Page 23: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Types of relationships

• One-to-one (l:l)—An occurrence of [object] 'A' can relate to one and only one occurrence of [object] 'B,' and an occurrence of 'B' can relate to only one occurrence of 'A.'

• One-to-many (l:N)—One occurrence of [object] 'A' can relate to one or many occurrences of [object] 'B,' but an occurrence of 'B' can relate to only one occurrence of 'A.’

• Many-to-many (M:N)—An occurrence of [object] 'A' can relate to one or more occurrences of 'B,' while an occurrence of 'B' can relate to one or more occurrences of 'A.’

Page 24: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Relationship types and Examples

One-to-many

Page 25: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Relationship types and Examples

Many-to-many

One-to-one

Page 26: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Relationship types and Examples

Page 27: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Examples

Page 28: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Exercise

Make ERD for a “has” relationship between patient and patient history entity types.

Make ERD for “is_assigned_to” relationship between employee and project entity types.

Page 29: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Associative EntityAn associative entity is an entity type that associates the instances or more entity types and contains attributes that are peculiar to the relationship between those entity instances.

Symbol:

Page 30: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

When to convert relationship to an associative entity type?

Following are four conditions that should exist:

All of the relationships for the participating entity types are “many” relationships.

The resulting associative entity type has independent meaning to end users, and preferably can be identified with a single-attribute identifier.

The associative entity has one or more attributes, in addition to the identifier.

The associative entity participates in one or more relationships independent of the entities related in the associated relationship.

Page 31: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Associative Entity-Example

Page 32: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Multiple RelationshipsIn some situations, an organization may wish to model more than one relationship between the same entity types.

Page 33: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Examples-Multiple Relationships

Page 34: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Enhanced E-R Model

The model that has resulted from extending the original E-R model with new modeling constructs.

The most important modeling construct incorporated in the EER model is super-type/subtype relationships. This facility enables us to model a general entity type (called the supertype) and then subdivide it into several specialized entity types (called subtypes).

For example the entity type CAR can be modeled as a supertype, with subtypes SEDAN, SPORTS CAR, COUPE, and so on.

Each subtype inherits attributes from its supertype and in addition may have special attributes and be involved in relationships of its own.

Page 35: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Representing supertypes and subtypes

Subtype: A subgrouping of the entities in an entity type that is meaningful to the organization and that shares common attributes or relationships distinct from other subgroupings.

Supertype: A generic entity type that has a relationship with one or more subtypes.

Page 36: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Basic Concepts and NotationThe supertype is connected with a line to a circle, which in turn is connected by a line to each subtype that has been defined.

The U-shaped symbol on each line connecting a subtype to the circle emphasizes that the subtype is a subset of the supertype. It also indicates the direction of the subtype/supertype relationship.

Page 37: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Basic Concepts and Notation (Contd.)

Page 38: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

ExampleSuppose that an organization has three basic types of employees: hourly employees, salaried employees, and contract consultants. Some of the important attributes for each of these types of employees are the following:

Hourly employees: Emp_Number, Emp_Name, Address, Date_Hired, Hourly_Rate

Salaried employees: Employee_Number, Employee_Name, Address, Date_Hired, Annual_Salary, Stock_Option

Contract consultants: Employee_Number, Employee_Name, Address, Date_Hired, Contract_Number, BiI1ing_Rate

Notice that all of the employee types have several attributes in common: Employee_Number, Employee_Name, Address, and Date_Hired. In addition, each type has one or more attributes distinct from the attributes of other types (e.g., Hourly_Rate is unique to hourly employees).

Page 39: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Employee supertype with three subtypes

Page 40: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

When to Use Supertype/Subtype RelationshipsWhether to use supertype/subtype relationships is a decision that the data modeler must make in each situation. You should consider using subtypes when either (or both) of the following conditions are present:

1. There are attributes that apply to some (but not all) instances of an entity type.

2. The instances of a subtype participate in a relationship unique to that subtype.

Page 41: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Supertype/subtype relationships in a hospital

Page 42: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Representing Specialization and GeneralizationGeneralization: The process of defining a more general entity type from a set of more specialized entity types.

Specialization: The process of defining one or more subtypes of the supertype and forming supertype/subtype relationships.

Page 43: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Example of generalization

Page 44: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Example of generalization (Contd.)

Page 45: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Example of Specialization

Page 46: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Example of Specialization (Contd.)

Page 47: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Specifying constraints in supertype/subtype relationshipsCompleteness constraint: A type of constraint that addresses the question whether an instance of a supertype must also be a member of at least one subtype.

Total specialization rule: Specifies that each entity instance of the supertype must be a member of some subtype in the relationship.

Partial specialization rule: Specifies that an entity instance of the supertype is allowed not to belong to any subtype.

Page 48: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Examples of completeness constraints

Page 49: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Examples of completeness constraints (Contd.)

Page 50: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Specifying constraints in supertype/subtype relationships (Contd.)Disjointncss constraint: A constraint that addresses the question whether an instance of a supertype may simultaneously be a member of two (or more) subtypes.

Disjoint rule: Specifies that if an entity instance (of a supertype) is a member of one subtype, it cannot simultaneously be a member of any other subtype.

Overlap rule: Specifies that an entity instance can simultaneously be a member of two (or more) subtypes.

Page 51: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Examples of disjointness constraints

Page 52: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

Examples of disjointness constraints (Contd.)

Page 53: Entity Relationship Modeling Chapter 11. Objectives ER Model Entity type Relationship type Attribute Cardinality and modality Symbols Examples

The End