Chapter 2 Database Design
Chapter 2 Database Design
JIT Fundamentals of
Faculty of computing Database systems
&Informatics
Chapter Two
Database Modeling
Database Design Goes Through Stages
Problem
Requirements Analysis
Data
Requirements Data Analysis, Conceptual Design
Conceptual
Schema
Logical Database Design
Logical Schema
Physical Database Design
Physical
Schema
Slide 3- 2
Conceptual and Logical Design
name
Relational
Model: (plus
functional
dependencies)
Normalization:
Slide 3- 3
Toy Example: University Database
Example queries we may want to ask:
Slide 3- 4
University Data Requirements
• A student has a name, which consists of a given name and a family
name, and a student ID. Each student is uniquely identified by
his/her student ID.
• A course has a subject and a course ID. For each course, we want to
record the number of students taking that course. A course is
uniquely identified by its course ID.
Slide 3- 5
University Data Requirements (cntd.)
• A student is also registered for a semester of study. A semester of
study is identified by the year number between 1 and 4, and
semester number between 1 and 2. A student is registered for only
one semester of study.
Slide 3- 6
Conceptual Design with the ER Model
The questions to ask:
• What are the entities (= objects, individuals)
in the organization?
• Which relationships exist among the entities?
• What information (= attributes) do we want to store
about these entities and relationships?
• What are the business rules of the organization?
• Which integrity constraints do arise from them?
Slide 3- 7
Entities and Entity Sets/Types
Entity: An object distinguishable from other objects
(e.g., an employee)
• An entity is described by a set of attributes.
Examples of entities?
Slide 3- 8
Graphical Representation of Entity Sets
given family
courseno
no. of
students CrHr
name
STUDENT COURSE
IDno name
Building
name
class
roomno
Slide 3- 10
Multi-valued
previousDegree
STUDENT
Examples of relationships?
Slide 3- 12
An Instance of a Relationship Type
Student Enrolled Course
St1 r1
C1
St2
r2 C2
St3
r3 C3
St4
r4
St5
….
St6 r5
…. r6
….
Slide 3- 13
Graphical Representation of
Relationship Types
given family
courseno
no. of
name labmark students equip
Slide 3- 14
Roles and Recursive Relationships
An entity type can
• participate in several name
relationship sets STAFF
and IDno
• participate more than once appraiser appraisee
in one relationship set Appraisal
(taking on different “roles”)
Slide 3- 15
Multiplicity (cardinality) of
Relationship Types
1 1
• one-one: 1 a
2 b
3 c
d 1
• many-one: 1 a
2 b
3 c
d
Slide 3- 16
Participation Constraints
Slide 3- 17
Mandatory Participation
Staff Works_for Department
St1 r1
D1
St2
r2 D2
St3
r3 D3
St4
r4
St5
….
St6 r5
…. r6
….
1
Staff Works_for Department
Slide 3- 18
Many:many Relationship Type
with Optional and Mandatory Participation
Staff Teaches Course
St1 r1 C1
St2
r2 C2
St3
C3
St4 r3
r4 C4
St5
….
….
r5
r6
….
Slide 3- 19
Recursive Relationship Type
with Optional Participation
Staff r1 Manages
St1 M
unmana St2 M
ged St3 E r2
E E
St4 r3
E M
St5 r4
E
St6 r5
…. M ….
M
Staff
M: Manager
E: Employee Manager Employee
Manages
Slide 3- 20
Summary: Properties of Relationship Types
Degree
– The number of participating entity types
Cardinality ratios
– The number of instances of each of the participating
entity types which can partake in a single instance
of the relationship type:
1:1, 1:many, many:1, many:many
Participation
– Whether an entity instance has to participate
in a relationship instance
– Represented with a double line
Slide 3- 21
Relationships of Higher Degree
Degree
n binary relationships
Slide 3- 22
Attributes in ER Modeling
• For every attribute we define
– Domain or data type
– Format, i.e., composite or atomic
– whether it is derived
Slide 3- 23
ER Model of the University DB
given family 1
SCHOO
studno name Reg L
hons
faculty
STUDENT
m year
YearReg
1
labmark YEAR
Enrolled Tutor 1
slot YearTut
exammark
or
1 1
n n name
courseno STAFF
m
COURSE Teach 1 m IDno
subject
appraiser appraisee
name
Apprais
al
Slide 3- 24
Multiway (non-binary) Relationship
Relationships can involve more than two entity
types…
roomno
STAFF
STAFF
name
p
given family courseno
equip
name TUTOR
m S n
COURSE
STUDENT
subject
studno
Slide 3- 25
Constraints: Definition
Slide 3- 26
Modeling Constraints
Finding constraints is part of the modeling process.
They reflect facts that hold in the world or
business rules of an organization.
Examples:
Keys: codice fiscale uniquely identifies a person
Single-value constraints: a person can have only one father
Referential integrity constraints: if you work for a company,
it must exist in the database
Domain constraints: peoples’ ages are between 0 and 150
Cardinality constraints: at most 100 students enroll in a course
Slide 3- 27
Keys
A key is a set of attributes that
uniquely identify an object or entity:
Slide 3- 28
Variants of Keys
• Multiple keys:
– E.g. social-security-number, name + address
Slide 3- 29
Existence Constraints
Sometimes, the existence of an entity of type X
depends on the existence of an entity of type
Y:
Examples:
• Book chapters presume the existence of a book
• Tracks on a CD presume the existence of the CD
• Orders depend on the existence of a customer
Slide 3- 32
SUMMARY OF ER-DIAGRAM
NOTATION FOR ER SCHEMAS
Symbol Meaning
ENTITY TYPE
RELATIONSHIP TYPE
ATTRIBUTE
KEY ATTRIBUTE
MULTIVALUED ATTRIBUTE
COMPOSITE ATTRIBUTE
DERIVED ATTRIBUTE
E1 R E2 TOTAL PARTICIPATION OF E2 IN R
Slide 3- 33
PROBLEM with ER notation
Slide 3- 34
Extended Entity-Relationship (EER) Model
Constraints on specialization/generalization
relationship ( Reading assignment)
Slide 3- 35
Specialization/Generalization
It is a relationships types between 2 entities; one
will be more general entity type and the other
entity type is specialized based on the general
entity.
A superclass is an entity type that includes one or
more distinct subgroupings of its occurrences,
Slide 3- 36
EER model
Example
Slide 3- 37
EER model
STAFF
Slide 3- 38
ER vs EER
Slide 3- 40
EER model
Attribute inheritance
Slide 3- 41
End!!!