Chapter 3: Data Modeling Using The Entity-Relationship Model
Chapter 3: Data Modeling Using The Entity-Relationship Model
Outline:
٣.١ Design Phases.
Phase 1: Requirements collection and analysis.
Phase 2: Conceptual Design.
Phase 3: Logical design (data model mapping).
Phase 4: Physical design.
1
3.1 Design Phases
Phase 1: Requirements collection and analysis
• Interview prospective database users to understand and document their data requirements
• The result of this phase is concisely written set of users’ requirements and functional
requirements of the application; consist of the user defined operations (or transactions) that will
be applied to the database, and they include both retrievals and updates).
• Conceptual schema for the database, using High-Level Conceptual Data Model (entity types,
relationships, and constraints).Because these concepts do not include implementation details,
they are usually easier to understand and can used to communicate with no technical users. The
high level conceptual schema can also be used as a reference to ensure that all users' data
requirements are met and that the requirements do not include conflicts.
• The result is Conceptual Schema in high level model
• The internal storage structures, access paths, and file organizations for the database files are
specified.
2
Mini-World
Database Requirements
DBMS-independent
Conceptual Data Model
DBMS-specific
Phase3: Logical Design
3
3.2 The Entity-Relationship (ER) Model
Used for conceptual database design
Relies on concepts of entities, attributes, and relationships
Entity: An entity is a "thing" (a being, an object, an event) in the real world and is
distinguishable from other objects (things).
Entity types represent sets of objects and are pictured by rectangular nodes
Entity Type
Characteristic of Entity:
• Existence: It may have a physical existence (also called concrete) (for example, car,
house, or an employee) in the real world or it may be an object with a conceptual
existence (abstract). (for example, a job, or a university course).
• Described by its attributes (set of properties); for example an EMPLOYEE entity may
have a Name, SSN, Address, Sex, BirthDate.
• Determined by particular value of its attributes; a specific entity will have a value for
each of its attributes(domain);
Example: a specific book entity will have title= “Database System Concepts”,
pages=821, ISBN= 0-07-044756-X
Example: A person name= “Mohammed”, age=21, add=salt
4
• Entity sets do not need to be disjoint. For example, it is possible to define the entity
set of all employees of a bank (employee) and the entity set of all customers of the bank
(customer). A person entity may be an employee entity, a customer entity, both, or
neither.
• An entity type defines a collection (or set) of entities that have the same attribute (for
example, employee entity type and company entity type). An entity is an instance of an
entity type. All entities having the same set of properties are grouped into an entity type.
• An entity set is the collection of all entities of a particular entity type in the database at
any point in time
Types of Attributes
Several types of attributes occur in the ER model (simple Vs. composite, single-valued Vs.
multivalued, Stored Vs. Derived Attribute, complex Attribute, and key Attribute)
o Each entity has a single atomic value for the attribute; for example SSN or Gender.
Simple Attribute
5
o Achieved by concatenating simpler attribute types. The attribute may be composed of
several components; for example Address (Street, City, State, and Postal Code) or
Name (First Name, Middle Name, and Last Name).
A Composite
Attribute
6
٣. Multivalued attribute types
o 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}.
Multivalued Attribute
o Some attribute values can be derived from related attributes or entities; for example
an attribute Age of employee entity can be determined from the current date and the
value of stored attribute (BirthDate).
Derived Simple
Attribute
٥. Complex Attribute
Number Name
StreetAddress City
PhoneNumber AreaCode
State
Zip
Phone Address
AddressPhone
7
Figure 3.6: AddressPhone Complex Attribute
o An attribute whose values are distinct for each individual entity in the collection. In
other words, 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.
Key Attribute
o An entity type may have more than one key. For example, the CAR entity type may
have two keys:
A. VehicleIdentificationNumber (popularly called VIN) and
B. VehicleTagNumber (Number, State), also known as license_plate
number.
o The following ER diagram for car:
OR
8
The following figure contains all of the above types of attributes:
Null Values
o In some cases a particular entity may not have an applicable value for an attribute.
Example, the ApartmentNumber attribute of an address applies only to addresses that
are in apartment buildings and not to single-family homes.
o If we do not know the value of an attribute for a particular entity. The unknown
category of null can be further classified into two cases:
A. The first case arises when it is known that the attribute value is applicable, but
it is missing—for example, if the height attribute of a person is listed as null.
B. The second case arises when it is not known whether the attribute value
applicable —for example, if the HomePhone attribute of a person is null.
Example: Appartment-Number attribute:
o Not applicable: if the address does not include a apartment-number.
o Missing: an apartment-number exists but we do not know what it is.
9
o Unknown: we do not know whether or not an apartment-number is part of the
customer’s address
Relationship
A relationship is an association among at least two entities belonging to one or more entity
sets. For example, EMPLOYEE Sami works for IT DEPARTMENT.
Relationship
Type
Example:
10
Department
Employee
A relationship set is the collection of instances (i.e., relationships between objects) represented
by a relationship type.
Relationship types may associate an entity type with itself. In such a case, the roles of the entity
types in the relationship type are listed on the edges, and the relationship is said to be recursive.
Pre-
requisite
Course
11
More than one relationship type can exist with the same participating entity types; for example
the WORKS_FOR relationship type in which EMPLOYEEs and DEPARTMENT participate,
or the MANAGES relationship type in which EMPLOYEEs and DEPARTMENTs participate.
Works
for
Employee Department
Manage
Figure 3.13:
Example: We can have two binary relationship types associating the student and team types,
TeamMemberOf and LeaderOf. In the former case, a student entity is a member of a team
entity; in the later case, a student can be a leader of a team.
Member
of
Student Team
Leader
of
Figure 3.14:
12
Hours/week
Figure 3.15:
o Example:
Since
Figure 3.16:
Price
Figure (1)
Price
Figure2
13
١. Unary: related to another of the same entity type. Also called recursive relationships.
Supervise
Supervisor Supervisee
Employee
٢. Binary: entities of two different types related to each other. (Two participating entities).
14
٣. Ternary: entities of three different types related to each other. (three participating
entities).
PartNo#
Part
Suppid Pname
Quantity
• Example:
Drug
Doctor Prescribe
Patient
15
٤. n-ary: entities of more than three different types related to each other.
Mapping cardinalities, or cardinality ratio, express the number of entities to which another
entity can be associated via a relationship set. (specifies maximum participation).
There are four types of cardinality: 1:1, 1:N, N:1, or M:N.
١. One-to-One (1:1) cardinality ratio, an entity in one set is associated with at most one entity
in another.
16
For Example:
Department
Employee
(Manager)
Abed Hossam
17
٢. One-to-many (1: N) cardinality ratio, an entity in the first set is associated with 0 or more
entities in the second set. However, those entities in the second set can be associated with
at most one entity in the first.
For Example:
TheAER
Project
Diagram is: Controlled by A Department
٣. Many-to-one (N: 1) cardinality ratio is just the reverse of the 1:N cardinality ratio. You
can think of whichever entity set you like as being the first set. Just specify the direction
18
that makes sense for your application, and then be consistent.
٤. Many-to-many (N:M) cardinality ratio, entities of either set may be associated with any
number of entities in the other.
19
For Example:
Projects
Jamal Sami
Employee
20
Employee Work on Project
21
The minimum value is one or more.
Every entity in E participates in at least one relationship in R
Shown by double line.
Partial Total
(min1..max1) (min2..max2)
E1 R E2
An employee can work for exactly one department but a department can have any number of
employees.
o Specify (1..1) for participation of EMPLOYEE in WORKS_FOR
o Specify (0..*) for participation of DEPARTMENT in WORKS_FOR
(1..1) (1..*)
Employee Works for Department
Prepared by: Sawsan Abu_TaleB and Randa Al_Dallah ©2009
22
Figure 3.34: many-to-one relationship type example using Min..Max notation.
A weak entity type must participate in an identifying relationship type with an owner or
identifying entity type.
Identifying relationship type is pictured by diamond with double lines.
Identifying
Relationship
Type
Partial Key
o The particular entity they are related to in the identifying entity type
A weak entity type may have more than one identifying entity type and an identifying
relationship type of degree higher than two.
For example:
SSN Name
23
Figure 3.35: Weak entity Example.
o A DEPENDENT entity is identified by the dependent’s first name, and the specific
EMPLOYEE with whom the dependent is related.
• Name of DEPENDENT is the partial key
• DEPENDENT is a weak entity type
• EMPLOYEE is its identifying entity type via the identifying relationship type
DEPENDENT OF.
24
3.5 An Example of Database Application (COMPANY Database)
The database designers stated the following description of the “miniworld”—the part of the
company to be represented in the database:
١. The company is organized into departments. Each department has a unique name, a unique
number, and a particular employee who manages the department. We keep track of the start
date when that employee began managing the department. A department may have several
locations.
٢. A department controls a number of projects, each of which has a unique name, a unique
number, and a single location.
٣. We store each employee’s name, social security number, address, salary, sex, and birth
date. An employee is assigned to one department but may work on several projects, which
are not necessarily controlled by the same department. We keep track of the number of
hours per week that an employee works on each project. We also keep track of the direct
supervisor of each employee.
٤. We want to keep track of the dependents of each employee for insurance purposes. We
keep each dependent’s first name, sex, birth date, and relationship to the employee.
25
Figure 3.36: The ER Diagram for the company DB.
26
Consider the following information about a university database:
Design and draw an ER diagram that captures the information about the University.
27