normalisation - smckearney.com · 4 4 normalisation steps each step in the process reduces the...
TRANSCRIPT
1
Normalisation
Connolly, Ch. 13
2
2
Overview
• Normalisation– Steps
• 1NF– Removing repeating groups
• 2NF– Partial dependencies
– Removing partial dependencies
• 3NF– Transitive dependencies
– Removing transitive dependencies
3
3
Normalisation
• “A formal technique for analysing relationsbased on their primary key and functionaldependencies.” [Codd].
• Process– Analyse each relation using a set of rules
– If a relation does meet a rule• Decompose the relation into two or more relations
4
4
Normalisation Steps
Each step in the process reduces the update anomalies that can occur.
0NF
1NF
2NF
3NF
BCNF
4NF
5NF
5
5
Unnormalised Form (0NF)
• A 0NF relation may have:– Multivalued attributes
• Some attributes have more than one value
– Composite attributes• Some attributes consist of multiple parts
– Nested relations• Some attributes contain another relation
6
6
0NF Example
Proj-id, Proj-Start-Date, Location and Weeks-on-Projectcontain multiple values
7
7
First Normal Form (1NF)
• Definition– “A relation in which the intersection of each row
and column contains one and only one value.”• “No repeating groups”
• A 1NF relation does not contain– Multivalued attributes
– Composite attributes
– Nested relations
8
8
Converting 0NF to 1NF
• “Remove repeating groups”– Start with a 0NF relation which contains...
• a key that identifies a set of attributes
• and a set of attributes that repeat
– Remove the repeating attributes and place them in aseparate relation
– Include a copy of the original key in the newrelation
9
9
1NF - Identify the Repeating Group
Key Repeating Group
10
10
1NF - Remove the Repeating GroupEmp1
EmpProj1
11
11
1NF Relations
Emp1(emp-no, emp-name, dept, manager)
EmpProj1(emp-no, proj-id, proj-start-date, location, weeks-on-project)
12
12
Second Normal Form (2NF)
• Definition– “A relation that is in 1NF and every non-primary-
key attribute is fully dependent on the primary key.”• “Remove partial dependencies”
• A 2NF relation is one that– Is in 1NF
– and contains no partial dependencies
13
13
Partial Dependency on the Key
• An attribute that is dependent on part of the key
(A, B, C, D)
AB → CA → D
D is partially dependent on the key (AB)
14
14
Converting 1NF to 2NF
• Identify all partial dependencies
• Ignore all relations with a single attributeprimary key
– This relation is in 2NF
• Create a new relation– Remove the partially determined attribute
– Copy part of the primary key
Emp1
15
15
2NF - Identify Partial Dependencies
EmpProj1
Proj-Start-Date is dependent on part of the key.
16
16
2NF - Remove Partial Dependency
Proj2
EmpProj2
Create a relation with the proj-start-date attribute and a copy of the proj-id attribute.
Remove the proj-start-dateattribute.
17
17
2NF Relations
Emp2(emp-no, emp-name, dept, manager)
EmpProj2(emp-no, proj-id, location, weeks-on-project)
Proj2(proj-id, proj-start-date)
18
18
Third Normal Form (3NF)
• Definition– “A relation that is in 2NF and every non-primary-
key attribute is dependent on the primary key only.”• “Remove transitive dependencies.”
• A 3NF relation is one that– Is in 3NF
– and contains no transitive dependencies
19
19
Transitive Dependency on the Key
• An attribute that is dependent on an attributeother than the key
(A, B, C, D)
AB → CC → D
D is transitively dependent on the key (AB)through C
20
20
Converting 2NF to 3NF
• Identify all transitive dependencies
• Ignore all relations with two attributes
• For each transitive dependency– Create a new relation
– Remove the transitively determined attribute
– Copy the determining attribute
Proj2
21
21
3NF - Identify Transitive Dependencies
Manager is dependent on a non-key attribute.
Emp2
22
22
3NF - Remove Transitive Dependency
Dept3
Emp3Remove the managerattribute.
Create a relation withthe manager attribute anda copy of the dept attribute.
23
23
3NF Relations
Emp3(emp-no, emp-name, dept)
Dept3(dept, manager)
EmpProj2(emp-no, proj-id, location, weeks-on-project)
Proj2(proj-id, proj-start-date)
24
24
Third Normal Form
Process1NF - Remove repeating groups
2NF - Remove partial dependencies
3NF - Remove transitive dependencies
Emp3
Dept3
Proj3
EmpProj3