31
. Dr Mohamed Osman Hegaz 1 Conceptual data base design: Conceptual data base design: The conceptual models: The conceptual models: The Entity Relationship Model The Entity Relationship Model

Dr. Mohamed Osman Hegaz1 Conceptual data base design: The conceptual models: The Entity Relationship Model

Embed Size (px)

Citation preview

Dr. Mohamed Osman Hegaz 1

Conceptual data base design:Conceptual data base design:The conceptual models: The conceptual models:

The Entity Relationship ModelThe Entity Relationship Model

Dr. Mohamed Osman Hegazi 2

Requirements specification

Database Design

Conceptual Database Design

Logical Database Design

Physical Database Design

Database implementation

Application Planning

Application Design

Application Implementation

Testing

Maintenance

ERUML

Mapping

Normalization

Design container , policy, Integrity

Create & Programming

Query processing and transaction

Database Administration

Dr. Mohamed Osman Hegaz 3

• Conceptual Design is an important phase in designing a successful database application.

• The Entity Relationship (ER) Model is one of the most widely used method for conceptual design.

• The ER Model can be neatly mapped to a Relational Schema.

Conceptual ModelingConceptual Modeling

Dr. Mohamed Osman Hegaz 4

Entities

– Entity Sets and Entity Types

– Attributes, Keys and Value Sets

Relationships

– Relationship Types and Sets

– Relationship Degree

– Roles and Recursive Relationships

– Relationship Constraints

– Attributes of Relationship Types

ER Model BasicsER Model Basics

Dr. Mohamed Osman Hegaz 5

ER Diagram BasicsER Diagram Basics

Dr. Mohamed Osman Hegaz 6

Defines set of entities that have the same attributes (e. g. EMPLOYEE).

• Each Entity Type is described by its NAME and Attributes.• The Entity Type describes the “Schema” for entities.• Entity Type and Entity Set are customarily referred to by the

same name.

Entity TypeEntity Type

Dr. Mohamed Osman Hegaz 7

• Key Attributes.• Null Valued Attributes.• Attribute Types – Composite Vs. Simple Attributes. – Single- valued Vs. Multi- valued Attributes. – Derived Vs. Stored Attributes.

Notation

AttributesAttributes

Dr. Mohamed Osman Hegaz 8

• Key attribute’s values are distinct for each individual extension in the entity set.

• A key attribute has its name underlined inside the oval.• Key must hold for every possible extension of the entity

type.• Multiple keys are possible

Key AttributesKey Attributes

Dr. Mohamed Osman Hegaz 9

• A particular entity may not have an applicable value for an attribute.

– Phd - Degree: Not applicable for a person with no university education.

– Home- Phone: Not known if it exists. – Height: Not known at present time.

• Type of Null Values – Not Applicable – Unknown – Missing

Null Valued AttributesNull Valued Attributes

29/09/2007 9

Dr. Mohamed Osman Hegaz 10

Composite attributes can be divided into smaller parts which represent simple attributes with independent meaning.

• Simple Attribute: B-Date• Complex Attribute: Name which is comprised of:

First name Mid name Last name

Composite Vs. Simple AttributesComposite Vs. Simple Attributes

29/09/2007 10Week_03

Dr. Mohamed Osman Hegaz 11

Simple attributes can either be single-valued or multi-valued.• Single-valued: Gender = F

Notation

• Multivalued: Degree = {BSc, Phd}

Notation

An “attribute” in the relational model is always single valued - Values are atomic!

Single Vs. Multivalued AttributesSingle Vs. Multivalued Attributes

11

Dr. Mohamed Osman Hegaz 12

Some attribute values can be derived from related attribute values:

• Age Date - B-day• Y-Sal 12 * M-Sal

Derived Vs. Stored AttributesDerived Vs. Stored Attributes

Dr. Mohamed Osman Hegaz 13

• Relationship Types and Sets.

• Relationship Degree.

• Entity Roles and Recursive Relationships.

• Relationship Constraints.

• Attributes of Relationship Types.

RelationshipsRelationships

Dr. Mohamed Osman Hegaz 14

A Relationship is an association among two or more entities (e.g. Students enroll in courses).

Relationship DegreeThe degree of a relationship type is the number of participating entity types.

2 entities: Binary Relationship 3 entities: Ternary Relationship n entities: N-ary Relationship

Same entity type could participate in multiple relationship types.

Relationship Types and SetsRelationship Types and Sets

Dr. Mohamed Osman Hegaz 15

• Each entity type that participates in a relationship type plays a particular role in the relationship type.

• The role name signifies the role that a participating entity from the entity type plays in each relationship instance, i.e. it explains what the relationship means.

Entity RolesEntity Roles

Dr. Mohamed Osman Hegaz 16

Recursive RelationshipsRecursive Relationships

• Same entity type can participate more than once in the same relationship type under different “roles”.

• Such relationships are called “Recursive Relationships”.

Dr. Mohamed Osman Hegaz 17

Kinds of Constraints

What kind of constraints can be defined in the ER Model?• Cardinality Constraints.• Participation Constraints.Together called “Structural Constraints”.

Constraints are represented by specific notation in the ER diagram.

Relationship ConstraintsRelationship Constraints

Dr. Mohamed Osman Hegaz 18

Cardinality RatioCardinality Ratio

The “Cardinality Ratio” for a binary relationship specifies the number of relationship instances that an entity can participate in.– Works-In is a binary relationship.– Participating entities are Department : Employee– One department can have Many employees Ratio is -Cardinality 1 : N

Dr. Mohamed Osman Hegaz 19

Possible Cardinality RatiosPossible Cardinality Ratios

1- to- 1 (1: 1)Both entities can participate inonly one relationship instance.

1- to Many Many- to- 1 (1: N, N: 1)One entity can participate inmany relationship instances.

Many- to- Many (N: M)Both entities can participate inmany relationship instances.

Dr. Mohamed Osman Hegaz 20

Example Cardinality ConstraintsExample Cardinality Constraints

• How many Employees can work in a Department? Many employee can work in only one department

• How many Employees can be employed by a Department? One department can employ many employees

• How many managers can a department have? One department can have only one manager

• How many departments can an employee manage? One employee can have manage only one department

Dr. Mohamed Osman Hegaz 21

Representing CardinalityRepresenting Cardinality

Many employee can work in only one departmentOne department can employ many employeesOne department can have only one managerOne employee can manage only one department

Dr. Mohamed Osman Hegaz 22

Existence DependencyExistence Dependency

Existence dependency indicates whether the existence of an entity depends on its relationship to another entity via the relationship type.

Every employee must work for a department - EMPLOYEE is existentially dependent on DEPARTMENT via the Works-In relationship type.

Dr. Mohamed Osman Hegaz 23

Kinds of participating constraintsKinds of participating constraints

TOTAL Participation (Existence Dependency)Constraint: Every employee must work for a department.

PARTIAL ParticipationConstraint: Not every employee is a manager.

Dr. Mohamed Osman Hegaz 24

Representing ParticipationRepresenting Participation

Every employee must work for a departmentEvery department must have a managerEvery department must have employeesNot every employee is a manager

Dr. Mohamed Osman Hegaz 25

Attributes of Relationship TypesAttributes of Relationship Types

Relationship Types can also have attributes just as entity types.

Dr. Mohamed Osman Hegaz 26

Weak EntitiesWeak Entities

• Entity types that do not have key attributes of their own are called “Weak Entities”.

• A weak entity can be identified uniquely only by considering the primary key of another “Owner” entity.

• The relationship type that relates a weak entity to its owner is called the “Identifying relationship”.

Dr. Mohamed Osman Hegaz 27

Weak EntitiesWeak Entities

• Owner and weak entity must participate in a 1: N relationship type.

• Weak entity must have total participation in the identifying relationship set (existence dependency).

• Weak entities normally have a “Partial Key”, which is a set of attributes that uniquely identify weak entities related to the same owner entity.

• Not every existence dependency results in a weak entity !

Dr. Mohamed Osman Hegaz 28

Example Weak EntityExample Weak Entity

28

Dr. Mohamed Osman Hegaz 2929Week_03

SUMMARY OF ER-DIAGRAM

Dr. Mohamed Osman Hegaz 30

Exercises:

Q1: Describe what entity types represent in an ER model. Q2: Describe what relationship types represent in an ER model. Q3: Describe what attributes represent in an ER model. Q4: Create an ER Diagram for each of the following descriptions:

Each company operates four departments, and each department belongs to one company.

Each department in part (a) employs one or more employees, and each employee works for one department.

Each of the employees in part (b) may or may not have one or more dependant, and each dependant belongs to one employee.

Each employee in part (c) may or may not have employment history. Represent all ER diagrams described in (a), (b), (c), and (d) as single ER

daigarm

Dr. Mohamed Osman Hegaz 31

Q5: Consider the company example, on ER diagram:Q5: Consider the company example, on ER diagram:List the (nonweak ) entity type in the ER.Is there weak entity type? If so give its name.List the names of all relation types, and specify the cardinality ratio. Is there recursive relationship? If so give its name.