Lecture 6 Normalization
Lecture 6 Normalization
Lecture 6 Normalization
lecture 6
In this lecture, you will learn
• Overview
• A little background and terminology:
• What is a relational database?
• What is a primary key?
• What is a foreign key?
• Things to know about designing a database:
• The normalization process and how/why use it
• Relating tables
• Types of relationships
Relational Database Management
System
• Collection of information organized in tables
• Tables are also “relations”
• Tables are constructed and associated to each other
through shared fields–“common” fields
– Fields are also “columns” or “attributes”
• A set of attributes comprises a record
– Records are also “rows” or “tuples”
• Tables are related through common fields designated as
primary and foreign keys
• Allow us to find, update, and delete data quickly, and
help to ensure accuracy
Primary and Foreign Key
Fields
• Primary Key
– Primary key fields must be unique and cannot contain
a null value.
• Each table should have a primary key field.
• Concatenated keys: using more than one field as a
primary key field.
• Foreign Key: Fields in a table that refer to the primary
key in another table
• The data in this field must exactly match data
contained in the primary key field.
What is Normalization?
• Consider
R(matrix_no,firstname,surname,tutor_no,tutor_name)
tutor_no -> tutor_name
– A given tutor_no uniquely identifies a tutor_name.
– An implied daterminant is also present:
• matrix_no -> firstname,surname,tutor_no,tutor_name
Extracting understanding
• Example:
– The Student table with the repeating group is not
in 1NF
– It has repeating groups, it is an `unnormalised
table'.
• To remove the repeating group, either:
– flatten the table and extend the key, or
– decompose the relation- leading to First Normal
Form
Flatten table and Extend Primary Key
• The Student table with the repeating group can be
written as:
Student(matric_no, name, date_of_birth, ( subject, grade ) )
Student
PKD
Fully Dependent
• This relation is not in 2NF
p1 Black,B 32 High Street
p3 Black,B 32 High Street
p4 Black,B 32 High Street
Extract
• Address depends on the value of manager.
p1 Black,B
• If we need to know a
manager's address we p2 Smith,J
can look it up in the
Manager relation p3 Black,B
p4 Black,B
• The manager attribute
is the link between the Manager manager address
two tables, and in the
Projects table it is now Black,B 32 High Street
a foreign key.
R(a,b,(c,d)) becomes
R(a,b)
R1(a,c,d)
Summary: 2NF
• A relation is in 2NF if it contains no repeating groups
and no partial key functional dependencies
– Rule: A relation in 1NF with a single key field must
be in 2NF
– To convert a relation with partial functional
dependencies to 2NF. create a set of new
relations:
• One relation for the attributes that are fully
dependent upon the key.
• One relation for each part of the key that has
partially dependent attributes