You are on page 1of 45

Databases Fundamentals

Session 3
The Relational Modelling

V1.0 © NCC Education Limited


Scope and Coverage
This topic will cover:
• Aims of the relational model
• Basic concepts of the relational model
• Terminology
• Relational integrity
• Normalisation
• Functional dependency
Learning Outcomes
By the end of this topic, students will be able to:
• Understand the aims of the relational model
• Understand the basic concepts of relational model
• Define key terms of the relational model
• Describe the types of relational integrity
• Describe the concept of functional dependency
• Recognise anomalies in relations
• Perform normalisation
Background to Relational Model
• Dominates the market in databases
• Second generation of DBMSs
• Developed by E.F. Codd in 1970
• In the relational model, all data is logically
structured in relations.
• Relations can be thought of as tables.
Do not confuse relations with
relationships in ER models
History – Theoretical Basis
• E. F. Codd’s 1970 paper “A relational model of data
for large shared data banks”
- There should be a high degree of data
independence.
- There should be a minimum of redundancy:
relations should be normalised.
- There should be a set-orientated data
manipulation language.
Data Independence
• Changes in the internal data representation,
such as file structure, storage and access paths
should not have an effect on the applications
programs.
Normalised Relations
• By having an underpinning in set theory, it is
possible to organise relations as sets so that there
is a minimum of data redundancy. This process is
known as normalisation.
Set-Orientated Data Manipulation
Languages
• Data can be manipulated by using set operations
since it will be organised in set-like relations.
History – Practical Developments - 1
• System R. Developed by IBM in late 1970s

Development of the SQL Development of


(Structured Query Language) commercial database
systems
DB2; SQL/DS; Oracle
History – Practical Developments - 2
• INGRESS. Developed by University of California in
late 1970s

The INGRESS commercial products


History - Practical Developments - 3
• Peterlee Relational Test Vehicle. Developed at
IBM UK in 1976

Theoretical insights into


Query Processing
Optimisation
Terminology -1
• Relation
• Attribute
• Domain
• Null
Attributes

Student ID First Name Last Name Course


Code
Relation

S334 Dave Watson COMP


S765 Jagpal Jutley COMP
S783 Cynthia Kodogo HIST
S111 Wallace Antigone LIT

Domain of valid course codes:


COMP, HIST, LIT etc.
Terminology - 2
• Tuple
• Degree
• Cardinality
• Relational Database
• Relational Schema
Student ID First Name Last Name Course
Code

Cardinality
4 Tuples

S334 Dave Watson COMP


S765 Jagpal Jutley COMP
S783 Cynthia Kodogo HIST
S111 Walace Antigone LIT

Degree
Alternative Terminology
Formal Term Alternative 1 Alternative 2

Relation Table File

Tuple Row Record

Attribute Column Field


Properties of a Relation - 1
• It has a name which is unique within the relational
schema.
• Each cell of a relation contains exactly one value.
• Each attribute has a name.
• Each tuple is unique.
• The order of attributes is insignificant.
• The order of tuples is insignificant.
Activity - Is This a Relation?
Student Name Course Programme
Guy Smith Med1 Medieval History History
1

Med2 Medieval History


2

TCE Twentieth Century


Sarah Anusiem OS Operating Systems Computing
12 New Street
Lagos NET Networks
Properties of a Relation - 2
• It has a name which is unique within the relational
schema - No
• Each cell of a relation contains exactly one value-No
• Each attribute has a name – YES
• Each tuple is unique - YES
• The order of attributes is insignificant – YES
• The order of tuples is insignificant - YES
Now a Relation - Still Problems
Students
Student Address Course Programme
Name
Guy Smith Med1 Medieval History 1 History

Guy Smith Med2 Medieval History 2 History


Guy Smith TCE Twentieth Century History

Sarah Anusiem 12 New Street OS Operating Systems Computing


Lagos
Sarah Anusiem 12 New Street NET Networks Computing
Lagos
Students
Turned into a Student ID Name Address Programme
set of normalised
28 Guy Smith History
relations...
23 Sarah 12 New Street Computing
Anusiem Lagos

Student Course
Student ID Course Code
Course
28 Net
Course Code Name
23 Med 1 Med1 Medieval History 1
28 OS OS Operating Systems

23 Med 2 Med2 Medieval History 2


NET Networks
TCE Twentieth Century
History
Student ID Name Address Programme
Keys...
28 Guy Smith History

23 Sarah 12 New Street Computing


Anusiem Lagos

Student ID Course Code

28 Net Primary keys


23 Med 1 Course Code Name

28 OS Med1 Medieval History 1

23 Med 2 OS Operating Systems


Med2 Medieval History 2
NET Networks
TCE Twentieth Century
History
Student ID Name Address Programme
Keys...
28 Guy Smith History

23 Sarah 12 New Street Computing


Foreign keys Anusiem Lagos

Student Course Code


ID Course Code Name

28 Net Med1 Medieval History 1


OS Operating
23 Med 1
Systems
28 OS Med2 Medieval History 2
23 Med 2 NET Networks
TCE Twentieth Century
History
Normalisation
• This process of moving from data that is not in a
relational form, to a relation, and finally to a set of
ideal relations is known as normalisation.

• We will be exploring normalisation more in the next


session...
Key Concepts Needed for Next
Session

• Primary key
• Super key
• Candidate key
• Foreign key
Relational Integrity
• Nulls

• Entity integrity

• Referential integrity

• General constraints
What is a Relation?
Students
Name Age Sex Student Major
Number
Singh 18 M 9901 English
Literature
Jones 18 F 9902 Geography
Lee 18 F 9922 Computing
O’Toole 18 M 9923 Geography
Choudhury 19 F 9811 Languages
Functional Dependence - 1
A relationship between attributes...

• A → B means B is functionally dependent on A - A


functionally determines B.

• For each value of A, there is associated one value


of B.
Functional Dependence - 2
Students
Student ID First Name Surname
9901 John Dacus
9902 Satpal Singh
9922 Jagpal Singh
9811 John Smith

• For any Student ID, there is one first name and one
surname
• But not the other way around...
Functional Dependence - 3
Students
Student ID First Name Surname
9901 John Dacus
9902 Satpal Singh
9922 Jagpal Singh
9811 John Smith

• For any Student ID, there is one first name and


one surname
• Student ID -> First Name, Surname
Activity - 1
Student ID Activity Fee
9901 Skiing 200
9902 Swimming 50
9922 Squash 50
9811 Swimming 50

• What might be a candidate key?

• What functional dependencies are going on


here?
Activity - 2
Student ID Activity Fee
9901 Skiing 200
9902 Swimming 50
9922 Squash 50
9811 Swimming 50

• What might be a candidate key?

• What functional dependencies are going on here?


Student ID, Activity -> Fee
Primary Key
Student ID Activity Fee
9901 Skiing 200
9902 Swimming 50
9922 Squash 50
9811 Swimming 50
9901 Swimming 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.
Activity: Anomalies
Student ID Activity Fee
9901 Skiing 200
9902 Swimming 50
9922 Squash 50
9811 Swimming 50

• What information do we lose if 9901 stops skiing?


Splitting the Relation
Student ID Activity
9901 Skiing
9902 Swimming Student_activity
9922 Squash
9811 Swimming

Activity Cost
Skiing 200
Activity_cost Swimming 50
Squash 50
The Document
Student Number: 1078654X
Student Name: David Green
Programme Code: G105
Programme Title: BA Business Computing

Course Code Course Title Number Grade Result Result


of Point Code
Credits
BUS119 Business 20 10 P Pass
Operations
COM110 Introduction to 20 8 P Pass
Computing
COM112 Application Building 20 3 RE Refer Exam
COM114 Software 20 2 DC Defer Coursework
Engineering
COM118 Computer Law 10 9 P Pass
COM120 Systems Analysis 20 3 RCE Refer coursework
and Exam
COM122 HCI 10 7 P Pass
UNF
1NF 2NF 3NF
LEVEL
Student Number 1 Student Number Student Number Student Number
Student Name 1 Student Name Student Name Student Name
Programme Code 1 Programme Code Programme Code Programme Code*
Programme Title 1 Programme Title Programme Title
Course Code 2 Specify
Programme repeating
Code
Course Title 2 group
Student Number* Student Number* information
Programme Title
No. of Credits 2 Course Code Course Code*
Grade Point 2 Course Title Grade Point Student Number*
Result Code 2 No. of Credits Result Code Course Code*
Result 2 Grade Point Result Grade Point
Result Code Result Code*
Result Course Code
Course Title Result Code
No. of Credits Result

Course Code
Course Title
No. of Credits
1NF- Remove Repeating Group Information
UNF
1NF 2NF 3NF
LEVEL
Student Number 1 Student Number Student Number Student Number
Student Name 1 Student Name Student Name Student Name
Programme Code 1 Programme Code Programme Code Programme Code*
Programme Title 1 Programme Title Programme Title
Course Code 2 Programme Code
Course Title 2 Student Number* Student Number* Programme Title
No. of Credits 2 Course Code Course Code*
Grade Point 2 Course Title Grade Point Student Number*
Result Code 2 No. of Credits Result Code Course Code*
Result 2 Grade Point Result Grade Point
Result Code Result Code*
Result Course Code
Course Title Result Code
No. of Credits Result

Course Code
Course Title
No. of Credits
2NF - Remove Partial Key Dependencies
UNF
1NF 2NF 3NF
LEVEL
Student Number 1 Student Number Student Number Student Number
Student Name 1 Student Name Student Name Student Name
Programme Code 1 Programme Code Programme Code Programme Code*
Programme Title 1 Programme Title Programme Title
Course Code 2 Programme Code
Course Title 2 Student Number* Student Number* Programme Title
No. of Credits 2 Course Code Course Code*
Grade Point 2 Course Title Grade Point Student Number*
Result Code 2 No. of Credits Result Code Course Code*
Result 2 Grade Point Result Grade Point
Result Code Result Code*
Result Course Code
Course Title Result Code
No. of Credits Result

Course Code
Course Title
No. of Credits
3NF - Remove Non-Key Dependencies
UNF
1NF 2NF 3NF
LEVEL
Student Number 1 Student Number Student Number Student Number
Student Name 1 Student Name Student Name Student Name
Programme Code 1 Programme Code Programme Code Programme Code*
Programme Title 1 Programme Title Programme Title
Course Code 2 Programme Code
Course Title 2 Student Number* Student Number* Programme Title
No. of Credits 2 Course Code Course Code*
Grade Point 2 Course Title Grade Point Student Number*
Result Code 2 No. of Credits Result Code Course Code*
Result 2 Grade Point Result Grade Point
Result Code Result Code*
Result Course Code
Course Title Result Code
No. of Credits Result

Course Code
Course Title
No. of Credits
3NF
Student
mber Student Number
e Student Name
Code Programme Code*
Title
Programme Code Programme
mber* Programme Title
*
Student Number*
Course Code* Student Course
Grade Point
Result Code*
e
Result Code
Result Type
s Result

Course Code
Course Title
Course
No. of Credits
3NF

mber Student Number


e Student Name
0...* 1
Code Programme Code*
Student Programme
Title
Programme Code
mber* Programme Title
*
Student Number*
Course Code*
Grade Point
Result Code*
e
A foreign key means we attach a
Result Code
s Result
‘many’ end on an entity relationship
diagram...
Course Code
Course Title
No. of Credits
Learning Outcomes – Have We
Met Them?
By the end of this topic, students will be able to:
• Understand the aims of the relational model
• Understand the basic concepts of relational model
• Define key terms of the relational model
• Describe the types of relational integrity
• Describe the concept of functional dependency
• Recognise anomalies in relations
• Perform normalisation
Any Questions?

You might also like