Data Modeling Using The Entity-Relationship Model
Data Modeling Using The Entity-Relationship Model
• Outline
– Using High-Level Conceptual Data Models for
Database Design
– Entity Types, Entity Sets, Attributes, and Keys
– Relationships, Relationship Types, Roles, and Structural
Constraints
– Weak Entity Types
– Refining the ER Design for the COMPANY Database
– ER Diagrams, Naming Conventions, and Design Issues
1
Phases of Database Design (Simplified)
User-defined operations
(transactions) •Entity t types
Data flow diagrams
•Relationships
•constraints
2
Using High-Level Conceptual Data Models for Database Design
3
Database Design
(cont…)
• Once all the requirements have been collected and analyzed, the
next step is to create a conceptual schema for the database
• The conceptual schema is a concise description of the data
requirements of the users and includes detailed descriptions of the
entity types relationships and constraints
• These are expressed using the concepts provided by the high-level
data model
• Because these concepts do not include implementation details, they
are usually easier to understand and can be used to communicate
with non-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
4
Database Design
(cont…)
5
Physical design
6
An example Application
7
Example (cont…)
8
Example (cont…)
9
ER Diagram for the company database
10
Entity Types, Entity Sets, Attributes, and Keys
12
Two entities and their attribute values
employee department
13
Types of Attributes
i) Composite Versus Simple (Atomic) Attributes
Composite attributes can be divided into smaller subparts,
which represent more basic attributes with independent
meanings.
•For example Address can be subdivided into ( city,state,
StreetAddress, State, and Zip).
Attributes that are not divisible are called simple or atomic
attributes.
Composite attributes can form a hierarchy; for example,
StreetAddress can be subdivided into three simple attributes,
Number, Street, and ApartmentNumber.
14
ii) Single-valued Versus Multivalued
Attributes
Single- valued : Attrubutes which has a single
value. Eg. Age of a person
Multivaued: attribute which has two or more
value. Eg. Color of a car, CollegeDegree etc
A multivalued attribute may have lower and
upper bounds on the number of values allowed
for each individual entity.
For example the college degree may be
Bachelor, Master and PhD. 15
iii) Stored Versus Derived Attributes
• In some cases two (or more) attribute values are related—for
example, the Age and BirthDate attributes of a person.
• For a particular person entity, the value of Age can be
determined from the current (today’s) date and the value of that
person’s BirthDate.
• Therefore, the Age attribute is hence called a derived attribute
and is said to be derivable from the BirthDate attribute, which
is called a stored attribute.
• Some attribute values can be derived from related entities; for
example, an attribute NumberOfEmployees of a department
entity can be derived by counting the number of employees
related to (working for) that department.
16
iv) Null Values
17
v) Complex Attributes
18
3.3.2 Entity Types, Entity Sets, Keys, and Value Sets
20
• Attribute names are enclosed in ovals and are
attached to their entity type by straight lines
• Composite attributes are attached to their
component attributes by straight lines
• Multivalued attributes are displayed in double
ovals.
• An 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
21
Key Attributes of an Entity Type
Uniqueness property must hold for every extension of the entity set
23
Fname Minit Lname Number
Name Name
Locations
Sex
NumberOf
SSN Address Employee
Department
Salary
Bdate EMPLOYEE
singled
multiple-valued
Entity type
key attribute
derived attribute
24
Value Sets (Domains) of Attributes
25
Initial Conceptual Design of the
COMPANY Database
• After defining several entities and attributes we can
redesign our Company database as follows. The
requirement which is refined is given below:
An entity type DEPARTMENT with attributes Name,
Number, Locations, Manager, and ManagerStartDate.
Locations is the only multivalued attribute.
We can specify that both Name and Number are
(separate) key attributes, because each was specified
to be unique.
An entity type PROJECT with attributes Name, Number,
Location, and ControllingDepartment.
26
Initial conceptual design
27
key attribute
key attribute
{ …. } : multivalued attribute
( ) : component of a composite attribute
28
Relationships, Relationship Types, Roles, and
Structural Constraints
29
Some instances of the WORKS_FOR relationship
many-to-one
30
Relationship Degree, Role Names, and
Recursive Relationships
31
The ternary relationship SUPPLY
S supplies part P to project J
32
Relationships as Attributes
• One can think of an attribute called Department of the EMPLOYEE entity type
whose value for each employee entity is (a reference to) the department entity
• Hence, the value set for this Department attribute is the set of all
DEPARTMENT entities.
•This is what we did in when we specified the initial design of the entity type
33
• However, when we think of a binary relationship as an attribute, we
always have two options.
• In this example, the alternative is to think of a multivalued attribute
Employees of the entity type DEPARTMENT whose values for each
department entity is the set of employee entities who work for that
department.
• The value set of this Employees attribute is the EMPLOYEE entity
set.
• Either of these two attributes—Department of EMPLOYEE or
Employees of DEPARTMENT—can represent the WORKS_FOR
relationship type.
• If both are represented, they are constrained to be inverses of each
other
34
• Each 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.
35
Role Names and Recursive Relationships
36
e5
39
WORK_ON M:N relationship
40
Participation Constraints and Existence Dependencies
HOUR
42
- For a 1:1 relationship type, a relationship attribute can be
migrated to either participating entity types.
StartDate
1 1
EMPLOYEE MANAGES DEPARTMENT
StartDate
N 1
EMPLOYEE WORKS_FOR DEPARTMENT
43
-For M:N relationship types, some attributes may be
determined by the combination of participating entities.
must be specified as relationship attributes
HOURS
M N
EMPLOYEE WORKS_ON PROJECT
44
Weak Entity Types (vs. Strong Entity types)
45
Example:
Suppose that a DEPENDENT entity is identified by the
dependent’s first name and birthdate, 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.
A weak entity type always has a total participation
constraint (existence dependency) with respect to its
identifying relationship.
46
Summary of ER diagram notation
48
ER diagram for the COMPANY Scheme