CSC3318
Database Management 1
Data Modeling Using the Entity
Relationship Model
Database Management 1
Outlines
ER Diagram:
Entities
Attributes
Keys weak entity
Domain
Relationship
Roles
Degrees of relationships
Cardinalities
Database Management 1
Database Design
Steps in building a database for an application:
Understand real-world domain being captured
Specify it using a database conceptual model (E/R)
Translate specification to model of DBMS (relational)
Create schema using DBMS commands (DDL)
Load data (DML)
Database Management 1
Entity Relationship Model (E/R)
Conceptual (high-level, semantic) data models: provide
concepts that are close to the way many users perceive
data. (Also called entity-based or object-based data
models.)
The Entity-Relationship model (ER) is a high-level
description of the structure of the DB.
The Entity-Relationship Diagram (ERD) is a graphical
model for representing the conceptual model for the
data.
A E/R models the DB using three element types:
Entities
Attributes
relationships Database Management 1
Database Management 1
What is a Database Application?
Refers to: A particular database + Associated
programs to implement the queries and updates
that has a user-friendly interfaces (GUIs).
Example: Bank database + programs to keep
track of the deposit & withdrawal.
Conceptual modeling is important in designing a
successful database application.
Database Management 1
Using High-Level Conceptual Data
Models of Database Design
Requirements collection and analysis
Conceptual schema
Logical design
Physical design
Database Management 1
Entities & Attributes
Entity: The basic object that the ER model
represent is an entity which is a thing in the real
world.
Physical existence: like a person, employee
Conceptual existing: like job, course
Attributes: The particular properties that
describes the entity.
E.g: an employee is described by: name, age,
address, salary, job.
An entity will have a value for each of its attributes.
Database Management 1
Entities and Attributes
Database Management 1
Attributes Types
(Composite vs Simple)
Composite Attributes: Divided into smaller
subparts e.g. name divided into first, initial,
last.
Simple Attributes: Attributes that are not
divisible e.g. salary.
Database Management 1
Single Valued vs Multivalued
Single Value: Most attributes are of this
types. E.g. age
Multivalued: Set of values for the same entity.
E.g. car colors, previous degrees.
Database Management 1
Multivalued Attributes
It is desirable to decompose multivalued
attribute to a separate entity. It might be a
1:N or M:N relationship.
Database Management 1
Stored vs Derived Attributes
Stored Attributes: regular attributes.
Derived attributes: are calculated from attributes
of one or several related entities.
E.g. calculating the salary from the hours worked
and number of hours.
Database Management 1
More Attributes Types
Null Values: some entities may not have an applicable
values for an attributes => a special value is created
called NULL. E.g. in the employee information the field of
mobile number can have a null value because some
employees do not have mobile phones.
Complex Attributes: composite and multivalued
attributes can be nested. E.g. a person may have many
certificate, each certificate has the subfield name, year
and level. Therefore, it is represented this way:
{certificate (name, year, level)}
{} represents multivalued () represents composite
attributes.
Database Management 1
Entities
Entity Types: is a collection of occurrences of
entities that have common properties. E.g.
employees.
Entity Instance: is a single occurrence of an
entity types. E.g. the student named Aseel
Mohammed.
Entity Set: a collection of all entities of a
particular entity types in the database at any
point in time. E.g. Employee refers to both the
type of entity + the current set of all employees
entity in the database.
Database Management 1
Key Attributes of an Entity Type
Key Attribute: is a key that identifies each entity
uniquely and has a distinct value. E.g. the name attribute
in the company entity is unique.
Candidate Key (CK): a set of attributes that uniquely
identify an instance of an entity. E.g. students can be
identified by SSN or ID.
Composite Key: is a key made from more than one
attribute. E.g. the flight can be uniquely identified by
flight number and flight date.
Alternate Key (AK): is a candidate key that is NOT
selected to be the primary key.
Database Management 1
Keys Example
Database Management 1
Composite Key in ERD
Database Management 1
Primary Key Attributes (PK)
Can be a single attribute or composite attribute.
Can be called identifier.
Weak entity may have no key.
Has the following criteria:
Should not change its value
Not null
Avoid intelligent keys
Substitute large composite keys with surrogate keys
(system generated keys for unique numbers)
Database Management 1
Choice of PK
Choice of Primary Key (PK) is based on:
Attribute length
Number of attributes required
Certainty of uniqueness
Database Management 1
Strong & Weak Entity Types
Weak Entity Type
The existence of a weak entity type depends on the existence of
a strong entity set; it must relate to the strong entity type via a
relationship type called identifying relationship.
The PK of a weak entity set is formed by the PK of its strong
entity type, plus a weak entity type discriminator attribute (Partial
key).
Database Management 1
Values Sets Domain of Attributes
Domain: the set of values that might be
assigned to the attribute for each individual
entity. E.g. ages of employees can be (16-70)
or names is a set of alphabetical characters
only
Not displayed in ER diagram
Database Management 1
Relationships
Relationship Type: R among n entity types E1, E2,
…En defines a set of associations among entities from
these types.
Each entity type participates in the relationship type R.
Relationships may have attributes.
Degree of relationship: number of entities participating
in the relation.
More than one relationship can exist with the same entity
types. E.g. an employee and department may have the
relationships: works for or manages.
Database Management 1
Roles
Role indicates the purpose that each
participating entity type plays in a relationship
(e.g. prerequisite, requester)
Database Management 1
Roles
Role can be used when two entities are
associated through more than one
relationship to classify the purpose of each
relationship
Database Management 1
Degree of Relationship Type
Degree of Relationship refers to number of
participating entity types in a relationship.
A relationship of degree one (1 entity types) is
unary (recursive).
A relationship of degree two (2 entity types) are
binary.
A relationship of degree three (3 entity types) are
ternary.
Database Management 1
Recursive Relationship
Recursive relationship is a relationship type
where the same entity type participates more
than once in a different role. It is a unary
relationship.
Has the degree 1
Database Management 1
Degree of Relationship Type
A relationship of degree two (2 entity types)
are binary.
Database Management 1
Degree of Relationship Type
A relationship of degree three (3 entity types)
are ternary. (e.g. registration of a student in
a course by a staff)
Database Management 1
Constraints on Relationships
Constraints on Relationship Types (Also
known as ratio constraints)
Maximum cardinality
One-to-one (1:1)
One-to-many (1:N) or Many-to-one (N:1)
Many-to-many
Minimum Cardinality (also called participation
constraint or existence dependency constraints)
Zero (optional participation, not existence-dependent)
One or more (mandatory, existence-dependent)
Database Management 1
Cardinalities
Cardinality ratio expresses the number of relationships
an entity can participate in.
Most useful in describing binary relationship types.
For a binary relationship type, the mapping cardinality
must be one of the following types:
One to one (1:1)
Many to one (M:1)
One to many (1:M)
Many to many (M:N)
Database Management 1
One-to-one Relationship
A professor chairs at most one department;
and a department is chaired by only one
professor.
Database Management 1
One-to-Many Relationship
A course is taught by at most one professor;
a professor teaches many courses.
Database Management 1
Many-to-One Relationship
A class requires one room; while a room can
be scheduled for many classes
Database Management 1
Database Management 1
Many-to-Many Relationship
A class enrolls many students; and each
student is enrolled in many classes.
Database Management 1
Database Management 1
Alternative (min, max) Notation for
Relationship Structural Constraints
Examples:
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:
Specify (1, 1) for participation of EMPLOYEE in WORKS_FOR
Specify (1, n) for participation of DEPARTMENT in
WORKS_FOR
Database Management 1
Alternative (min, max) Notation for
Relationship Structural Constraints
Database Management 1
COMPANY ER Schema Diagram
using (min, max) notation
Database Management 1
Summary of ER Notations
Database Management 1
Cont..
Database Management 1