Uploaded by stem vendor

DB Topic 6

advertisement
Topic 6 – The Relational Model 2
Databases
Databases
Topic 6:
The Relational Model 2
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.2
Scope and Coverage
This topic will cover:
•
•
•
•
•
Relational integrity
Normalisation
Anomalies
Functional dependency
The process of normalisation
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.3
Learning Outcomes
By the end of this topic, students will be able to:
•
•
•
•
V1.0
V1.0
Describe the types of relational integrity
Describe the concept of functional dependency
Recognise anomalies in relations
Normalise a paper-type form
© NCC Education Limited
Visuals Handout – Page 1
Topic 6 – The Relational Model 2
Databases
The Relational Model 2 Topic 6 - 6.4
Relational Integrity
• Nulls
• Entity integrity
• Referential integrity
• General constraints
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.5
What is a Relation?
Students
Name
Age
Sex
Singh
18
M
Student
Number
9901
Jones
Lee
O’Toole
Choudhury
18
18
18
19
F
F
M
F
9902
9922
9923
9811
V1.0
Major
English
Literature
Geography
Computing
Geography
Languages
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.6
Functional Dependence - 1
A relationship between attributes...
• A  B means B is functionally dependent on A - A
functionally determines B
B.
• For each value of A, there is associated one value
of B.
V1.0
V1.0
© NCC Education Limited
Visuals Handout – Page 2
Topic 6 – The Relational Model 2
Databases
The Relational Model 2 Topic 6 - 6.7
Functional Dependence - 2
Students
Student ID
9901
9902
9922
9901
First Name
John
Satpal
Jagpal
gp
John
Surname
Dacus
Singh
Singh
g
Smith
• For any Student ID, there is one first name and one
surname
• But not the other way around...
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.8
Functional Dependence - 3
Students
Student ID
9901
9902
9922
9901
First Name
John
Satpal
Jagpal
gp
John
Surname
Dacus
Singh
Singh
g
Smith
• For any Student ID, there is one first name and
one surname
• Student ID -> First Name, Surname
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.9
Activity - 1
Student ID
9901
9902
9922
9811
Activity
Skiing
Swimming
Squash
Swimming
Fee
200
50
50
50
• What might be a candidate key?
• What functional dependencies are going on
here?
V1.0
V1.0
© NCC Education Limited
Visuals Handout – Page 3
Topic 6 – The Relational Model 2
Databases
The Relational Model 2 Topic 6 - 6.10
Activity - 2
Student ID
9901
9902
9922
9811
Activity
Skiing
Swimming
Squash
Swimming
Fee
200
50
50
50
• What might be a candidate key?
• What functional dependencies are going on here?
Student ID, Activity -> Fee
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.11
Primary Key
Student ID
9901
9902
9922
9811
9901
990
Activity
Skiing
Swimming
Squash
Swimming
Swimming
S
g
Fee
200
50
50
50
50
• Student ID is not a candidate key on its own.
• When we have identified a candidate key, we can
choose the primary key - in this case Student ID
and Activity.
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.12
Activity: Anomalies
Student ID
9901
9902
9922
9811
Activity
Skiing
Swimming
Squash
Swimming
g
Fee
200
50
50
50
• What information do we lose if 9901 stops skiing?
V1.0
V1.0
© NCC Education Limited
Visuals Handout – Page 4
Topic 6 – The Relational Model 2
Databases
The Relational Model 2 Topic 6 - 6.13
Splitting the Relation
Student ID
9901
9902
9922
9811
Activity
Skiing
Swimming
Squash
Swimming
Student_activity
Activity
Skiing
Swimming
Squash
Activity_cost
Cost
200
50
50
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.14
The Document
Student Number: 1078654X
Student Name: David Green
Course Code: G105
Course Title: BA Business Computing
Module Code
Module Title
BUS119
COM118
COM120
Business
Operations
Introduction to
Computing
Application Building
Software
Engineering
Computer Law
Systems Analysis
COM122
HCI
COM110
COM112
COM114
Number
of
Credits
20
Grade
Point
Result
Code
Result
10
P
Pass
20
8
P
Pass
20
20
3
2
RE
DC
Refer Exam
Defer Coursework
10
20
9
3
P
RCE
10
7
P
Pass
Refer coursework
and Exam
Pass
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.15
UNF
Student Number
Student Name
Course Code
Course Title
Module Code
Module Title
No. of Credits
Grade Point
Result Code
Result
V1.0
V1.0
UNF
LEVEL
1
1
1
1
2
2
2
2
2
2
Specify repeating
group information
© NCC Education Limited
Visuals Handout – Page 5
Topic 6 – The Relational Model 2
Databases
The Relational Model 2 Topic 6 - 6.16
1NF
- Remove Repeating Group Information
UNF
Student
Number
Student Name
Course Code
C
Course
Titl
Title
Module Code
Module Title
No. of Credits
Grade Point
Result Code
Result
UNF
LEVEL
1
1
1
1
2
2
2
2
2
2
1NF
Student Number
Student Name
Course Code
Course Title
Student Number*
Module Code
Module Title
No. of Credits
Grade Point
Result Code
Result
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.17
2NF
- Remove Partial Key Dependencies
UNF
Student Number
Student Name
Course Code
Course Title
Module Code
Module Title
No. of Credits
Grade Point
Result Code
Result
UNF
LEVEL
1
1
1
1
2
2
2
2
2
2
1NF
2NF
Student Number
Student Name
Course Code
Course Title
Student Number
Student Name
Course Code
Course Title
Student Number*
Number
Module Code
Module Title
No. of Credits
Grade Point
Result Code
Result
Student Number*
Number
Module Code*
Grade Point
Result Code
Result
Module Code
Module Title
No. of Credits
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.18
3NF
- Remove Non-Key Dependencies
Student
Number
Student Name
Course Code
Course Title
Module Code
Module Title
No. of Credits
Grade Point
Result Code
Result
UNF
LEVEL
1
1
1
1
2
2
2
2
2
2
1NF
2NF
3NF
Student Number
Student Name
Course Code
Course Title
Student
Number
Student Name
Course Code
Course Title
Student
Number
Student Name
Course Code*
Student Number*
Module Code
Module Title
No. of Credits
Grade Point
Result Code
Result
Student
Number*
Module Code*
Grade Point
Result Code
Result
Module Code
Module Title
No. of Credits
Course Code
Course Title
Student
Number*
Module Code*
Grade Point
Result Code*
Result Code
Result
Module Code
Module Title
No. of Credits
V1.0
V1.0
© NCC Education Limited
Visuals Handout – Page 6
Topic 6 – The Relational Model 2
Databases
The Relational Model 2 Topic 6 - 6.19
3NF
Student
Number
Student Name
Course Code*
Course Code
Course Title
Student
Number*
Module Code*
Grade Point
Result Code*
Result Code
Result
Module Code
Module Title
No. of Credits
Student
Course
Student Module
Result Type
Module
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.20
3NF
Student
Number
Student Name
Course Code*
Student
0...*
1
Course
Course Code
Course Title
Student
Number*
Module Code*
Grade Point
Result Code*
Result Code
Result
A foreign key means we attach a
‘many’ end on an entity relationship
diagram...
Module Code
Module Title
No. of Credits
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.21
Learning Outcomes – Have We
Met Them?
By the end of this topic, students will be able to:
•
•
•
•
V1.0
V1.0
Describe the types of relational integrity
Describe the concept of functional dependency
Recognise anomalies in relations
Normalise a paper-type form
© NCC Education Limited
Visuals Handout – Page 7
Topic 6 – The Relational Model 2
Databases
The Relational Model 2 Topic 6 - 6.22
References
• Connolly, T. & Begg, C. (2004). Database
Systems: A Practical Approach to Design,
Implementation, and Management, 4th Edition.
Addison Wesley. Chapter 3.
V1.0
© NCC Education Limited
The Relational Model 2 Topic 6 - 6.23
Topic 6 – The Relational Model 2
Any Questions?
V1.0
V1.0
© NCC Education Limited
Visuals Handout – Page 8
Download