Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model
Alternative (min, max) notation for relationship structural constraints
Example:
A department has exactly one manager and an
employee can manage at most one department.
Specify (0,1) for participation of EMPLOYEE in MANAGES
Specify (1,1) for participation of DEPARTMENT in MANAGES
An employee can work for exactly one
department but a department can have any
number of employees.
37 trang |
Chia sẻ: vutrong32 | Lượt xem: 1313 | Lượt tải: 0
Bạn đang xem trước 20 trang tài liệu Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Chapter 3
Data Modeling Using
the Entity-Relationship (ER) Model
ER Model Concepts
ER Model (Entity-relationship model): describes
data as entities, attributes and relationships.
Entities: Entities are specific objects or things in
the mini-world that are represented in the
database. The basic object that the ER model
represents is an entity,
Example: the EMPLOYEE John Smith.
Attributes: are properties used to describe an
entity. Each entity has attributes.
Example: an EMPLOYEE entity may have a
Name, Address, Sex, Birthdate.
ER Model Concepts
A specific entity will have a value for each of its
attributes.
Example: a specific employee entity may have
Name='John Smith', Address ='731, Fondren,
Houston, TX', Sex='M', BirthDate='09-JAN-55‘
Each attribute has a value set (or data type)
associated with it – e.g. integer, string,
enumerated type,
Types of Attributes
Simple (or atomic): Attributes that are not
divisible. For example, Sexual, SSN(Social Security
number),
Composite: Attributes can be divided into smaller
subparts, which represent more basic attributes
with independent meanings.
Example:
Address (Apt#, House#, Street, City, State,
ZipCode, Country)
Name (FirstName, MiddleName, LastName).
Composition may form a hierarchy where some
components are themselves composite.
Types of Attributes
Types of Attributes
Multi-valued: In some cases an attribute can have
a set of values for the same entity
Example:
Color of a CAR
Previous Degrees of a STUDENT.
A multivalued attribute may have lower and
upper bounds to constrain the number of values
allowed for each individual entity.
Types of Attributes
Complex Attributes:
Composite and multivalued attributes can be
nested in an arbitrary way.
Arbitrary nesting is represented by grouping
components of a composite attribute between
parentheses () and separating the components
with commas, and by displaying multivalued
attributes between braces {}.
Example:
{AddressPhone({Phone(AreaCode, PhoneNumber)},
Address(StreetAddress(Number, Street, ApartmentNumber), City,State,Zip) ) }
Entity Types and Key Attributes
Entity type: Entities with the same basic attributes
are grouped or typed into an entity type. For
example, the EMPLOYEE entity type.
Key Attributes: An entity type usually has an
attribute whose values are distinct for each
individual entity in the entity set. Such an attribute
is called a key attribute, and its values can be used
to identify each entity uniquely.
Entity Types and Key Attributes
A key attribute may be composite. For example,
VehicleTagNumber is a key of the CAR entity type
with components (Number, State).
An entity type may have more than one key. For
example, the CAR entity type may have two keys:
VehicleIdentificationNumber (popularly called VIN)
VehicleTagNumber (Number, State), also known as
license_plate number.
Entity Types and Key Attributes
Entity Types and Key Attributes
NOTATION FOR ER SCHEMAS
Entity Type
Weak entity type
Relationship type
Identifying relationship type
Attribute
Key attribute
Multivalued attribute
Composite attribute
Derived attribute
Total participation of E2 in R
Cardinality ratio 1:n for E1:E2 in r
Structural constraint (min, max) on participation
of E in R
E1 R E2
E1 R E2
R
(min,max)
E
N
Relationships and Relationship Types
A relationship: relates two or more distinct
entities with a specific meaning.
Example: EMPLOYEE John Smith works on the
ProductX PROJECT.
A relationship type R among n entity types E1,
E2, , En defines a set of associations among
entities from these entity types.
Example, the WORKS_ON relationship type in
which EMPLOYEEs and PROJECTs participate.
Relationships and Relationship Types
Relationships and Relationship Types
More than one relationship type can exist with the
same participating entity types.
Example: MANAGES and WORKS_FOR are distinct
relationships between EMPLOYEE and
DEPARTMENT, but with different meanings and
different relationship instances.
Relationships and Relationship Types
Relationship Degree
The degree of a relationship type is the number of
participating entity types.
Binary: A relationship type of degree two
Example: Both MANAGES and WORKS_ON are
binary relationships
Ternary: Relationship types of degree three
n-ary: Relationship types of degree n.
Relationship Degree
Role Names,
and Recursive Relationships
Role Names: Each entity type that participates in a
relationship type plays a role in the relationship.
The role name signifies the role that a participating
entity from the entity type plays in each
relationship instance.
Recursive relationships: The same entity type
participates more than once in a relationship type
in different roles.
Role Names,
and Recursive Relationships
For example, SUPERVISION relationships between
EMPLOYEE (in role of supervisor or boss) and
(another) EMPLOYEE (in role of subordinate or
worker).
Role Names,
and Recursive Relationships
Recursive Relationship Type is: SUPERVISION
(participation role names are shown)
Example COMPANY Database
Requirements of the Company:
The company is organized into DEPARTMENTs.
Each department has a name, number and an
employee who manages the department.
Each department controls a number of PROJECTs.
Each project has a name, number and is located
at a single location.
We store each EMPLOYEE’s social security
number, address, salary, sex, and birthdate.
Example COMPANY Database
Each employee works for one department but
may work on several projects.
We keep track of the number of hours per week
that an employee currently works on each
project.
We also keep track of the direct supervisor of
each employee.
Each employee may have a number of
DEPENDENTs. For each dependent, we keep
track of their name, sex, birthdate, and
relationship to employee.
Initial Conceptual Design of the
COMPANY Database
Initial Conceptual Design of the
COMPANY Database
Weak Entity Types
An entity that does not have a key attribute
A weak entity must participate in an identifying
relationship type with an owner or identifying
entity type
Entities are identified by the combination of:
A partial key of the weak entity type
The particular entity they are related to in the
identifying entity type
Weak Entity Types
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
Constraints on Relationship Types
Maximum Cardinality (The cardinality ratio) for
a binary relationship specifies the maximum
number of relationship instances that an entity can
participate in.
One-to-one (1:1)
One-to-many (1:N) or Many-to-one (N:1)
Many-to-many
Minimum Cardinality (participation constraint or
existence dependency constraints)
Zero (optional participation, not existence-
dependent)
One or more (mandatory, existence-dependent)
Constraints on Relationship Types
Constraints on Relationship Types
Constraints on Relationship Types
Cardinality ratios for binary relationships are
represented on ER diagrams by displaying 1, M,
and N.
Attributes of Relationship types
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.
Attributes of Relationship types
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 minmax, min0, max 1
Derived from the knowledge of mini-world
constraints
Alternative (min, max) notation for
relationship structural constraints
Example:
A department has exactly one manager and an
employee can manage at most one department.
Specify (0,1) for participation of EMPLOYEE in
MANAGES
Specify (1,1) for participation of DEPARTMENT
in MANAGES
An employee can work for exactly one
department but a department can have any
number of employees.
Alternative (min, max) notation for
relationship structural constraints
Specify (1,1) for participation of EMPLOYEE in
WORKS_FOR
Specify (0,n) for participation of DEPARTMENT
in WORKS_FOR
COMPANY ER Schema Diagram
using (min, max) notation
Các file đính kèm theo tài liệu này:
- chapter3_6454.pdf