#Lecture 3 FDB
#Lecture 3 FDB
Arsi University
1
Fundamental of Database
Systems
Lecture Three
Database Modelling
Arsi University
Kedir E.
Outline
3
3.1 The Entity Relationship (ER) Model
3.1.1. The high-level conceptual model
3.1.2. Entities, Attributes, and Keys
3.1.3. Relationships, Associations, and Constraints
3.1.4 The ER diagrams representation
3.1.5. Mapping ER-models to relational tables
3.2. Enhanced Entity Relationship (EER) Model
3.2.1. Inheritance
3.2.2. Union
3.2.3. Aggregation and Association
3.2.4. Mapping EER model to relational model
3.3. The Relational Database Model
3.3.1. The Relational Model Concepts
3.3.2. The Relational Constraints and Relational Database Schemas
3.3.3. The Relational Operations
Arsi University
3.1 The Entity Relationship (ER) Model
4
An Entity Relationship (ER) Diagram is a type of flowchart that
illustrates how “entities” such as people, objects or concepts relate
to each other within a system.
ER Diagrams are most often used to design or debug relational
databases in the fields of software engineering, business
information systems, education and research.
Also known as ERDs or ER Models, they use a defined set of
symbols such as rectangles, diamonds, ovals and connecting lines
to depict the interconnectedness of entities, relationships and their
attributes.
Cont’d…
5
Example: Company Database
6
We need to create a database schema design based on the following
(simplified) requirements of the COMPANY Database:
The company is organized into DEPARTMENTs. Each
department has a name, number and an employee who
manages the department. We keep track of the start date of the
department manager. A department may have several locations.
Each department controls a number of PROJECTs. Each
project has a unique name, unique number and is located at a
single location.
Example: Company Database …
7
We store each EMPLOYEE’s social security number,
address, salary, sex, and birthdate.
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 the employee.
3.1.2. Entities, Attributes and keys
8
Entities are specific objects or things in the mini-world that
are represented in the database.
For example the EMPLOYEE John Smith, the Research DEPARTMENT, the ProductX
PROJECT
Example
Person: employee, student, patient
Place : store, building
Object: sale, registration, renewal
Concepts: account, course
Entities …
11
An entity set is a set of entities of the same type that share the
same properties, or attributes.
The set of all persons who are customers at a given bank, for
example, can be defined as the entity set customer
Entity sets do not need to be disjoint. For example, it is possible to
define the entity Set of all employees of bank (employee) the entity
set of all customers of the bank (customer) a person entity may be
an employee entity ,a customer entity, both, or neither.
Entities …
12
Entity Types
Entities with the same basic attributes are grouped or typed into an
entity type.
For example, the entity type EMPLOYEE and PROJECT.
Composite
The attribute may be composed of several components. For example:
Address (Apt#, House#, Street, City, State, ZipCode, Country), or
Name (FirstName, MiddleName, LastName).
Composition may form a hierarchy where some components are themselves composite.
Multi-valued
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}.
Types of Attributes …
21
In general, composite and multi-valued attributes may be
nested arbitrarily to any number of levels, although this is
rare.
For example, PreviousDegrees of a STUDENT is a
composite multi-valued attribute denoted by
{PreviousDegrees (College, Year, Degree, Field)}
Multiple PreviousDegrees values can exist
Each has four subcomponent attributes:
College, Year, Degree, Field
Types of Attributes …
22
Example of Composite attribute
Types of Attributes …
Stored vs. Derived Attribute 23
26
Relationships and relationship types
A relationship relates two or more distinct entities with a
specific meaning.
For example, EMPLOYEE John Smith works on the ProductX PROJECT,
or EMPLOYEE Franklin Wong manages the Research DEPARTMENT.
Doctors patient
Relationships…
28
TERNARY RELATIONSHIP: Tuples/records of three different entities are
associated
Role can be used when two entities are associated through more than one
relationship to classify the purpose of each relationship.
Relationship…
Relationship Type: 30
32
By examining the requirements, six relationship types are identified
All are binary relationships( degree 2)
Listed below with their participating entity types:
WORKS_FOR (between EMPLOYEE, DEPARTMENT)
MANAGES (also between EMPLOYEE, DEPARTMENT)
CONTROLS (between DEPARTMENT, PROJECT)
WORKS_ON (between EMPLOYEE, PROJECT)
SUPERVISION (between EMPLOYEE (as subordinate),
EMPLOYEE (as supervisor))
DEPENDENTS_OF (between EMPLOYEE, DEPENDENT)
Discussion on Relationship Types
In the refined design, some 33attributes from the initial
entity types are refined into relationships:
Manager of DEPARTMENT -> MANAGES
Works_on of EMPLOYEE -> WORKS_ON
Department of EMPLOYEE -> WORKS_FOR
etc
In general, more than one relationship type can exist
between the same participating entity types
MANAGES and WORKS_FOR are distinct relationship types
between EMPLOYEE and DEPARTMENT
Different meanings and different relationship instances.
Recursive Relationship Type
The same entity participates 34
in a relationship set more
than once then it is called recursive relationship set.
An relationship type whose with the same participating
entity type in distinct roles
Example: the SUPERVISION relationship
EMPLOYEE participates twice in two distinct roles:
supervisor (or boss) role
supervisee (or subordinate) role
Each relationship instance relates two distinct EMPLOYEE entities:
One employee in supervisor role
One employee in supervisee role
Constraints on Relationships
35
Constraints on Relationship Types
(Also known as ratio constraints)
Cardinality Ratio (specifies maximum participation)
One-to-one (1:1)
One-to-many (1:N) or Many-to-one (N:1)
Many-to-many (M:N)
Existence Dependency Constraint (specifies minimum
participation) (also called participation constraint)
zero (optional participation, not existence-dependent)
Constraints on Relationships …
One-to-one (1:1): 36
one tuple is associated with only one
other tuple.
41
Attributes of Relationship types
42
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.
A value of HoursPerWeek depends on a particular
(employee, project) combination
Most relationship attributes are used with M:N relationships
In 1:N relationships, they can be transferred to the entity
type on the N-side of the relationship
Alternative diagrammatic notation
43
ER diagrams is one popular example for
displaying database schemas
Many other notations exist in the literature and in
various database design and modeling tools
Appendix A illustrates some of the alternative
notations that have been used
UML class diagrams is representative of another way
of displaying ER concepts that is used in several
commercial design tools
Summary of notation for ER diagrams
44
UML class diagrams
45
Represent classes (similar to entity types) as large rounded
boxes with three sections:
Top section includes entity type (class) name
Second section includes attributes
Third section includes class operations (operations are not in basic
ER model)
Relationships (called associations) represented as lines
connecting the classes
Other UML terminology also differs from ER terminology
Used in database design and object-oriented software design
UML class diagram for COMPANY database schema
46
Other alternative diagrammatic notations
47
Data Modelling Tools
48
A number of popular tools that cover conceptual modeling and
mapping into relational schema design.
Examples: ERWin, S- Designer (Enterprise Application Suite), ER-
Studio, etc.
POSITIVES:
Serves as documentation of application requirements, easy user
interface - mostly graphics editor support
NEGATIVES:
Most tools lack a proper distinct notation for relationships with
relationship attributes
Mostly represent a relational design in a diagrammatic form rather
than a conceptual ER-based design
3.1.4. Entity - Relation Diagram Representation
49
E-R diagram can express the overall logical structure of a database
graphically.
E-R diagrams are simple and clear-qualities that may well account
in large part for the widespread use of the E-R model.
Steps to create ER Diagram
Cont’d…
50
Cont’d…
51
Cont’d…
52
E-R diagram with composite, multivalued, and derived
attributes.
Cont’d…
53
Simple ER diagram
Cont’d…
Ex2: ER diagram for music54database
Cont’d…
55
Ex3: ER diagram for University database
Cont’d…
Ex4: ER diagram for Flight56database
Cont’d…
57
Exercise 1: Build an ER diagram for the following
information
65
Soln:
Mapping Employee entity 66
Specialization
Specialization is the process of defining a set of
subclasses of a superclass
The set of subclasses is based upon some distinguishing
characteristics of the entities in the superclass
Example: {SECRETARY, ENGINEER, TECHNICIAN} is
a specialization of EMPLOYEE based upon job type.
May have several specializations of the same superclass
Specialization …
81
Example: Another specialization of EMPLOYEE based on method
of pay is {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}.
Superclass/subclass relationships and specialization can be
diagrammatically represented in EER diagrams
Attributes of a subclass are called specific or local attributes.
For example, the attribute TypingSpeed of SECRETARY
The subclass can also participate in specific relationship types.
For example, a relationship BELONGS_TO of HOURLY_EMPLOYEE
Specialization …
82
Generalization
83
Generalization is the reverse of the specialization process
Several classes with common features are generalized into a
superclass;
original classes become its subclasses
Example: CAR, TRUCK generalized into VEHICLE;
both CAR, TRUCK become subclasses of the superclass VEHICLE.
We can view {CAR, TRUCK} as a specialization of VEHICLE
Alternatively, we can view VEHICLE as a generalization of CAR and
TRUCK
Generalization …
84
Generalization and Specialization
85
Diagrammatic notation are sometimes used to distinguish
between generalization and specialization
Arrow pointing to the generalized superclass represents a
generalization
Arrows pointing to the specialized subclasses represent a
specialization
We do not use this notation because it is often subjective as
to which process is more appropriate for a particular
situation
Generalization and Specialization …
86
Data Modeling with Specialization and
Generalization
A superclass or subclass represents a collection (or
set or grouping) of entities
It also represents a particular type of entity
Shown in rectangles in EER diagrams (as are entity
types)
We can call all entity types (and their corresponding
collections) classes, whether they are entity types,
superclasses, or subclasses
Constraints on Specialization and Generalization
87
If we can determine exactly those entities that will
become members of each subclass by a condition,
the subclasses are called predicate-defined (or
condition-defined) subclasses
Condition is a constraint that determines subclass
members
Display a predicate-defined subclass by writing the
predicate condition next to the line attaching the
subclass to its superclass
Constraints on Specialization and Generalization
… 88
If all subclasses in a specialization have membership
condition on same attribute of the superclass, specialization
is called an attribute-defined specialization
Attribute is called the defining attribute of the specialization
Example: JobType is the defining attribute of the specialization
{SECRETARY, TECHNICIAN, ENGINEER} of EMPLOYEE
If no condition determines membership, the subclass is
called user-defined
Membership in a subclass is determined by the database users
by applying an operation to add an entity to the subclass
Membership in the subclass is specified individually for each
entity in the superclass by the user
Displaying an attribute-defined specialization in
EER diagrams 89
Constraints on Specialization and Generalization
90
Example:
CUSTOMER (Cust-id, Cust-name, Address, Phone#)
CUSTOMER is the relation name
Defined over the four attributes: Cust-id, Cust-name, Address,
Phone#
Each attribute has a domain or a set of valid values.
For example, the domain of Cust-id is 6 digit numbers.
Informal Definitions - Tuple
115
A tuple is an ordered set of values (enclosed in angled
brackets ‘< … >’)
Each value is derived from an appropriate domain.
A row in the CUSTOMER relation is a 4-tuple and would
consist of four values, for example:
<632895, "John Smith", "101 Main St. Atlanta, GA 30332",
"(404) 894-2000">
This is called a 4-tuple as it has 4 values
A tuple (row) in the CUSTOMER relation.
A relation is a set of such tuples (rows)
Informal Definitions - Domain
116
A domain has a logical definition:
Example: “USA_phone_numbers” are the set of 10 digit phone
numbers valid in the U.S.
A domain also has a data-type or a format defined for it.
The USA_phone_numbers may have a format: (ddd)ddd-dddd where
each d is a decimal digit.
Dates have various formats such as year, month, date
formatted as yyyy-mm-dd, or as dd mm,yyyy etc.
123
Characteristics Of Relations
124
Values in a tuple:
All values are considered atomic (indivisible).
Each value in a tuple must be from the domain of the
attribute for that column
If tuple t = <v1, v2, …, vn> is a tuple (row) in the
relation state r of R(A1, A2, …, An)
Then each vi must be a value from dom(Ai)
127