3 DB Er
3 DB Er
Database Systems
Conceptual Modeling
1
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
2
Conceptual and Logical Design
name
Relational Model:
(plus functional
dependencies)
Normalization:
3
Toy Example: University Database
Example queries we may want to ask:
• Which are the given and the family name of the student
with student number 5432?
• How many students are enrolled for the course
“Introduction to Databases”?
• For which courses is Georg Egger enrolled?
• Which machine equipment is used for Introduction to
Databases?
4
More Example Queries
• At which school and for which course is Georg Egger
enrolled?
5
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 and the type of equipment being
used for the course. A course is uniquely identified by its course ID.
6
University Data Requirements (cntd.)
• A student is also registered for a year of study. An year of study is identified
by a number between 1 and 4. A student is registered for only one year of
study, but each cohort can have many students.
• For each member of staff we want to record their name and their room
number. A member of staff is identified by the combination of these two
pieces of data. Staff are appraised by other staff. A member of staff has no
more than one appraiser.
• For each year of study, there is one member of staff who acts as the year
tutor. A member of staff can only be responsible for one year of study.
Students can be registered for a year of study.
• Courses are taught by members of staff. A course can have several teachers,
and a staff member can teach several courses.
7
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?
8
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?
Examples of things that are not entities?
STUDENT COURSE
studno subject
name
STAFF
roomno
Examples of relationships?
12
An Instance of a Relationship Type
Student Enrolled Course
St1 r1
C1
St2
r2
St3 C2
r3 C3
St4
r4
St5
….
St6 r5
…. r6
….
given family
courseno
no. of
name labmark students equip
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
1
Staff Works_for Department
18
Optional and Mandatory Participation
Staff Manages Department
St1 r1 D1
St2
St3 D2
r2
D3
St4
r3
St5
….
St6
….
….
1
Staff Manages Department
19
Many:many Relationship Type
with Optional and Mandatory Participation
Staff Teaches Course
St1 r1 C1
St2
r2 C2
St3
C3
St4 r3
C4
St5 r4
….
….
r5
r6
….
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
22
Attributes in ER Modeling
• For every attribute we define
– Domain or data type
– Format, i.e., composite or atomic
– whether it is derived
23
ER Model of the University DB
given family 1
SCHOOL
studno name Reg
hons
faculty
STUDENT
m year
YearReg
1
labmark YEAR
Enrolled Tutor 1
slot YearTutor
exammark
1 1
n n name
courseno STAFF
m
COURSE Teach 1 m roomno
subject
appraiser appraisee
equip
Appraisal 24
Exercise: Supervision of PhD Students
A database needs to be developed that keeps track of PhD students:
• For each lecturer store the name, staff ID and office number. Staff ID's
are unique.
25
Exercise: Supervision of PhD Students
• For each research topic store the title and a short description. Titles
are unique.
Task:
Design an entity relationship diagram that covers the requirements
above. Do not forget to include cardinality and participation
constraints.
26
Multivalued Attributes
• Students often have more than one phone number (home,
student hall, mobile)
• There is no additional information, other than the number,
we need to store
• This captured by a multivalued attribute
• Notation: double-lined oval
given family
studno name
STUDENT phone_no
27
Roles in Non-recursive Relationships
given family
name
1 SUPERVISE m name
studno
STAFF STUDENT
1 m
EXAMINE
roomno
roomno
STAFF
STAFF
name
p
given family courseno
equip
name TUTORS
m n
COURSE
STUDENT
slot
subject
studno
29
Constraints: Definition
30
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
31
Keys
A key is a set of attributes that
uniquely identify an object or entity:
• Multiple keys:
– E.g. social-security-number, name + address
33
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
ORDER
Weak entity
date
35
Strong and Weak Entities
(Identifier Dependency)
• A strong entity type has an identifying primary key
• A weak entity’s key comes not (completely) from its own attributes,
but from the keys of one or more entities to which it is linked by a
supporting many-one relationship
• A weak entity type does not have a primary key
but does have a discriminator
customer
CUSTOMER
address
1
CUST-ORDER
m orderid
ORDER
36
date
Weak Entities May Depend on
Other Weak Entities
• Strong entity type c-name
• Identifying entity for CUSTOMER
ORDER address
1
• Identifying entity for
LINE_ITEM CUST-ORDER
m orderid
• Weak entity
• Identifying entity for ORDER
LINE_ITEM date
1
ORDER-MAKEUP
m
lineno
• Weak entity type LINE_
ITEM quantity
37
Turning Relationships into Entities
Relationship types are less natural if
• the relationships have many attributes, or
• we want to model a relationship with that relationship type
Example:
exammark
labmark
m n
STUDENT ENROL COURSE
TUTOR
STAFF
38
Association Entity Types
An entity type that represents a relationship type:
given family
courseno
equip
name
m studno
STUDENT COURSE
1 subject 1
m m
STUD_ENROL ENROL COURSE_ENROL
labmark exammark
STAFF
given family
courseno
equip
name
STUDENT
m studno TUTOR
COURSE
1 subject 1
m m
STUD_ENROL ENROL COURSE_ENROL
labmark exammark
41
“Don’t Say the Same Thing More Than Once”
Redundancy wastes space and encourages inconsistency
Example:
1
Beer ManfBy Manf
name manf
Which is good design,
and which is bad?
Beer Manf
addr
Why? 42
And What About This?
1
Beer ManfBy Manf
43
Entities Vs. Attributes
Sometime it is not clear
• which concepts are worthy of being entities, and
• which are handled more simply as attributes
Example:
Which are the pros and cons of each of
the two designs below?
1
Beer ManfBy Manf Beer
44
Entity Vs. Attribute: Rules of Thumb
45
Entity Vs. Attribute: Example
The following design illustrates both points:
1
Beer ManfBy Manf
Example:
If the university wants to associate only one instructor
with a course,
– don't allow sets of instructors and
– don’t count on departments to enter only one instructor
per course
48
Exercise: A Record Company Database
• A record company wishes to use a computer database to help with its
operations regarding its performers, recordings and song catalogue.
• A song can appear on many (or no) CDs, and be recorded by many
different recording artists. The same recording artist might re-record
the same song on different CDs. A CD must have only 1 recording
artist appearing on it. CDs can be released a number of times, and
each time the release date and associated number of sales is
required.
49
Superclasses and Subclasses:
The Problem
Suppose we want to model that:
• Students can be either undergraduates or graduates,
and every student belongs to one of these groups
• Among the university employees, there are academic,
administrative, and technical staff
(and there may be others)
• Only undergraduate students have tutors,
which are academics
50
Superclasses and Subclasses:
Specialisation and Generalisation
Subclasses and Superclasses
– A subclass entity type is a specialized type of a
superclass entity type
– A subclass entity type represents a subset or
subgrouping of the superclass entity type’s instances
Attribute Inheritance
– Subclasses inherit properties (attributes) of their
superclasses
51
Defining Superclasses and Subclasses
• Specialisation
– The process of defining a set of more specialised entity types of
an entity type
• Generalization
– The process of defining a generalised entity type from a set of
entity types
Completeness
• Total
– every entity instance in the superclass must be a member of some
subclass in the specialisation
• Partial
– an entity instance in the superclass need not be a member of any
subclass in the specialisation
53
Students are Undergraduates or
Postgraduates
• Undergraduates and
Postgraduates are subclasses
of Student given family
• The classes of undergraduates
name
and postgraduates are disjoint
m studno
STUDENT
• Every student is in one of either
class
d
STAFF
year
∩
∩
1
thesis title
m
Tutor UNDERGRADUATE POSTGRADUATE
54
Subclasses of Staff
• Academic, technical,
and admin are three payroll no name
STAFF
subclasses of staff
length of service
• The three classes
may overlap
o
∩
level
∩ ∩ grade
project
55
Subclasses in the University Scenario
• Every person has a name and an address. A person is
uniquely identified by their name.
56
Subclasses in the University Scenario
• Every student is either a postgraduate student or an
undergraduate student.
address
∩
∩
salary
fee
EMPLOYEE STUDENT
O thesis d
∩
∩
∩
∩
RESEARCH TEACHING POST UNDER
GRAD GRAD
O
∩
year = 3
∩
∩
project
courseno 58
References
In preparing these slides I have used several sources.
The main ones are the following:
Books:
• A First Course in Database Systems, by J. Ullman and J. Widom
• Fundamentals of Database Systems, by R. Elmasri and S. Navathe
59