1 DBMS EntityRelationshipModel
1 DBMS EntityRelationshipModel
Entity-Relationship
Model
COMP2411
What is Data?
Data is recorded or observable facts such as
age, address, height, etc.
Data is everywhere and there is a lot of it
Each piece of data takes up space on a
computer, so how do we store it efficiently and
effectively?
Student ID Student name Year Course Course Name
Grade
50000000 Peter Wong 4 CM2411 Database Systems
B+
50000000 Peter Wong 4 CS2302 Data Structures
A
50000000 Peter Wong 4 …. ….
..
50000001 Mary Tsui 2 CM2411 Database Systems
A-
50000002 Bob Lee 3 CM2411 Database Systems
B
Databases and the
DBMS
What is a Database (DB)?
◦ A non-redundant, persistent collection of logically
related records/files that are structured to support
various processing and retrieval needs
Sales DB
Marketing DBMS
Databases and the
DBMS
Difference between DBMS and other
programming systems
◦ the ability to manage persistent data
◦ Primary goal of DBMS: to provide an environment that
is convenient, efficient, and robust to use in retrieving
& storing data
Other DBMS capabilities
◦ data modeling
◦ high-level languages to define, access and manipulate
data
◦ transaction management & concurrency control
◦ access control
◦ recovery
Data Abstraction
Databases can be complex and depending on
your role what you need to understand about
the system is limited
Data Abstraction is simplifying or hiding details
of the data depending on what you need to
know
Levels of Abstraction (Lowest to Highest)
◦ Physical/Internal Level: How data is actually stored on
disk/cloud
◦ Logical/Conceptual Level: The schema, what data is
actually stored
◦ External/View Level: A partial schema, irrelevant
information is removed or simplified
Data Abstraction
COMP Student Finance Office
External Level
view 1 view 2 ..……... view n
Data Schema
◦ Each level of Data Abstraction is defined by a schema
◦ Logical Schema: Defines the logical/conceptual structure of
the database
◦ Physical Schema: Defines the file formats/locations
Data Instance
◦ The actual contents of the database at a specific period of
time
◦ The instance conforms to the schema
Data Independence
Data Independence is the ability to modify a
schema at one level without affecting schemas
at higher levels
Physical Data Independence
◦ The ability to modify the physical schema without
altering the conceptual schema and thus, without
causing the application programs to be rewritten
Logical Data Independence
◦ The ability to modify the conceptual schema without
causing the application programs to be rewritten
Data Independence
COMP Student Finance Office
External Level
view 1 view 2 ..……... view n
Applicatio Applicatio
n n (SQL) DB schema
query
interfaces programs
Application Database
programs manager
object code DBMS
File manager
Data files DB
Data dict.
disk storage
System Architecture
File Manager
◦ Allocates space on disk/cloud and controls operations
on files
Database Manager
◦ Interfaces between stored data and applications
programs/queries
◦ Translates conceptual commands to physical
commands
◦ Responsible for:
◦ Access Control
◦ Concurrency Control
◦ Backup and Recovery
◦ Integrity
System Architecture
Query Processor
◦ Translates high-level queries into tangible instructions
◦ Optimizes queries to improve performance
DML (Pre-)compiler
◦ Translates DML statements embedded in application
programs into procedure calls
DDL (Pre-)compiler
◦ Converts DDL states to data dictionary items (e.g. table
descriptions)
Application Sophisticated
Naïve user DBA
Programmer user
Applicatio Applicatio
n n (SQL) DB schema
query
interfaces programs
Application Database
programs manager
object code DBMS
File manager
Data files DB
Data dict.
disk storage
Course Topics
ER Model: Plan the data in your database and how they
related to each other
Relational Model: Turn a conceptual ER diagram into
tables/schema
SQL: The language of writing queries
Relational Algebra: A logical way to represent queries
Normalization and Integrity Constraints: Making tables
efficient and robust
File Organization: Structure files to speed up queries
Query Optimization: Make queries more efficient
Transaction and Concurrency Controls: Handle concurrent
operations and guarantee correctness of the DB
The Entity-Relationship
Model
The most widely understood database model, it
is a logical schema for record-based databases
Proposed by P. Chen in 1976
ER Diagrams are a critical tool of efficiently
conveying the structure of the DB
Entities
An Entity is a real-world ‘thing’ or ‘object’ which
is distinguishable from other objects via its
attributes
◦ Examples: John Chan, PolyU, HSBC, etc.
StudentID Date_of_Birth
Name Address
Student
Spot the Entities and
Attributes
“I would like to create a network for our PolyU
cinema. Each movie has has a MovieID, title, and
genre. Each screening includes has a
ScreeningID, date and time, and room. The
customers record their name, email and unique
customer number. A movie can have multiple
screenings and each customer can attend
multiple screenings. Also, customers can give as
many movies as they want a rating.
Based on this project brief, what are the entities and
their attributes for this potential database?
Relationships
A Relationship is an association among two or
more entities
◦ Example: Student John Chan takes the Course
COMP2411
A Relationship Set is the set of relationships of
the same type connecting the same Entity Sets
◦ Example: Students take Courses
Name Title
Supervisor
Employee Supervises
Supervisee
Relationship Degree
Sometimes 3 entities are involved in a
relationship, in which case this is referred to as
a Ternary Relationship
◦ A ternary relationship can sometimes be broken into 3
binary relationships but not always
For a relationship with n entities, this is called a
n-ary Relationship
◦ This is exceedingly rare for n > 3
Student Takes Course
Lecturer
Relationship Degree
Are these two different?
Lecturer
Name Address
Student
The Primary Key
When the Primary Key consists of two or more
attributes, this is called a Composite Primary
Key and all attributes in the Primary Key are
underlined
In Strong Entities, these are rare and when they
exist are often replaced with the use of an ID for
elegance assuming physical memory permits
Name
Name Number ProjectID Number
Project Project
Spot the Primary Keys
“I would like to create a network for our PolyU
cinema. Each movie has has a MovieID, title, and
genre. Each screening includes has a
ScreeningID, date and time, and room. The
customers record their name, email and unique
customer number. A movie can have multiple
screenings and each customer can attend
multiple screenings. Also, customers can give as
many movies as they want a rating.
Based on this project brief, what are the entities and
their relationships for this potential database?
Other Attribute Types
Multivalued Attribute:
When an Entity may have
Phone#
multiple different instances
of the same attribute
Derived Attribute:
An attribute which can be
Age
derived from other
information (e.g. Age can
be derived from Date of
Birth)
GivenName FamilyName Composite Attribute:
An attribute which can be
broken up into smaller
Name attributes which combine
to form a whole
Attribute vs Entity
Sometimes it seems difficult to decide whether
something should be an attribute or an entity
◦ Example: The degree of a student
Address District
Name
StudentID Date_of_Birth
Student
Phone# Age
Address Relationship
Relationship Constraints
Relationships also have constraints given to
them based on what these relationships are
describing
1: 1 1: N N: 1 N: M
Cardinality Constraints
On an ER diagram, this is denoted by labels on
the lines connecting the entities to the
relationships
1 1
1: 1 Staff Heads Department
1 N
1: N Department Offers Course
N M
N: M Students Takes Course
Spot the Relationships
“I would like to create a network for our PolyU
cinema. Each movie has has a MovieID, title, and
genre. Each screening includes has a
ScreeningID, date, time, and room. The
customers record their name, email and unique
customer number. A movie can have multiple
screenings and each customer can attend
multiple screenings. Also, customers can give as
many movies as they want a rating.”
What are the relationships and their cardinalities?
Can we assume any participation constraints?
ScreeningID MovieID
Room Title
Date N 1
Screening Has Movie
Time Genre
N
M
Attends
Rates
M
N
Customer# Customer Rating
Name
Email
Cardinality Constraints
Cardinality Constraints for Ternary Relationships
read the same way
N M
Student Takes Course
Lecturer
(0,N) (1,1)
Department Offers Course
(1,4) (1,N)
Students Takes Course
(1, 4) (1, 3)
Student Sessions Course
(1, 2)
Lecturer