Normal forms - 1NF, 2NF, 3NF 1 Normal forms - 1NF, 2NF and 3NF (under the assumption of relations...
-
Upload
abigail-potter -
Category
Documents
-
view
219 -
download
5
Transcript of Normal forms - 1NF, 2NF, 3NF 1 Normal forms - 1NF, 2NF and 3NF (under the assumption of relations...
Normal forms - 1NF, 2NF, 3NF
1
Normal forms - 1NF, 2NF and 3NF
(under the assumption of relations with just one candidate key)
Normal forms - 1NF, 2NF, 3NF
2
Aim
to familiarise with the concept of a normal form simplifying assumption (SA)
every relation has one candidate key only, which is, therefore, the primary key
Normal forms - 1NF, 2NF, 3NF
3
Generalities
normal forms• expressing FD constraints through choosing the
structure of relations (structure the component attributes)
• 3NF 2NF 1NF
transforming a relation into a higher normal form
• (vertical) decomposition - projection• non-loss decomposition
Normal forms - 1NF, 2NF, 3NF
4
1NF
a relation is in 1NF if and only if all the domains of its attributes contain only scalar values
Normal forms - 1NF, 2NF, 3NF
5
Relation in 1NF : Students-Info
Students-InfoS_id S_name S_addr M_id M_name Type Value Res
F122 M. Kent UB8 DB1 Databases 2sem 1cu 72%F122 M. Kent UB8 P01 Programming 2sem 1cu 62%F122 M. Kent UB8 SWE SWare Eng 2sem 1cu 65%F122 M. Kent UB8 FYP Fin Year Proj proj 1cu NULLP141 S. Brown SE14 DB1 Databases 2sem 1cu 68%P141 S. Brown SE14 IS01 Info. Sys. 1sem 0.5cu 76%P141 S. Brown SE14 DS Decision Sup 1sem 0.5cu NULLF87 P. Wild MN6 DB2 Databases 1sem 0.5cu NULL… … … … … … … …
Normal forms - 1NF, 2NF, 3NF
6
1NF - update anomalies
insert: exercise delete: exercise modify (update)
• suppose “Databases” changes to “3sem” and “1.5cu”
• the modification must be performed in more than one tuple; it implies a search;
• this structure (1NF) does not enforce consistent data; i.e. inconsistencies can be generated (e.g. by mistake)
• (implementation aspect) an update (involving a search) can be expressed by means of a single SQL statement, but
– the search still has to be performed– an incorrect statement can generate inconsistencies
Normal forms - 1NF, 2NF, 3NF
7
FD diagram for 1NF
S_idRes
S_name
S_addr M_id
TypeM_name Value
not all the determinants are the primary key
Normal forms - 1NF, 2NF, 3NF
8
2NF
A relation (with just one CK) is in 2NF if and only if it is in 1NF and every non-key attribute is irreducibly dependent on the primary key
“Students-Info” is not 2NF; • it can be decomposed into a set of relations in 2NF• the equivalence must be preserved
Normal forms - 1NF, 2NF, 3NF
9
Non-loss decomposition
a decomposition of R into its projections R1, …, Rn is non-loss if and only if the natural join of R1, …, Rn results in the initial R
Normal forms - 1NF, 2NF, 3NF
10
Non-loss decomposition
Students ModulesS_id S_name S_addr M_id M_name Type Value
F122 M. Kent UB8 DB1 Databases 2sem 1cuP141 S. Brown SE14 P01 Programming 2sem 1cuF87 P. Wild MN6 SWE SWare Eng 2sem 1cu… … … FYP Fin Year Proj proj 1cu
IS01 Info. Sys. 1sem 0.5cuDS Decision Sup 1sem 0.5cuDB2 Databases 1sem 0.5cu… … … …
Stud-ModS_id M_id Res
F122 DB1 72%F122 P01 62%F122 SWE 65%F122 FYP NULLP141 DB1 68%P141 IS01 76%P141 DS NULLF87 DB2 NULL… … …
Normal forms - 1NF, 2NF, 3NF
11
Activity
consider different relations and experiment with different decompositions - identify which ones are lossy and which ones are non-loss
Normal forms - 1NF, 2NF, 3NF
12
Heath’s theorem
Suppose A, B and C are sets of attributes of a relation R, such that
• AB and • heading(R) = A B C
then• R = {A, B} JOIN {A, C}
Normal forms - 1NF, 2NF, 3NF
13
Pragmatic principles
when you apply Heath’s theorem look for a maximum set of attributes B
• this will minimise the number of tables in the database
try to maintain a one to one correspondence with real life entities
Normal forms - 1NF, 2NF, 3NF
14
2NF - update anomalies
consider the relation “Module” insert
• insert that a “3sem” module is worth “1.5cu”
delete• exercise
modify (update)• exercise
Normal forms - 1NF, 2NF, 3NF
15
FD for 2NF
M_id
TypeM_name Value
transitive dependency
Normal forms - 1NF, 2NF, 3NF
16
3NF
A relation (with just one CK) is in 3NF if and only if it is in 2NF and every non-key attribute is non-transitively dependent on primary key
alternatively …• if there are no FDs between non-key attributes
Normal forms - 1NF, 2NF, 3NF
17
Modules - decomposed (non-loss)
Modules-Descr Type-Val-CorrespondenceM_id M_name Type Type ValueDB1 Databases 2sem 1sem 0.5cuP01 Programming 2sem 2sem 1cuSWE SWare Eng 2sem proj 1cuFYP Fin Year Proj proj … …IS01 Info. Sys. 1semDS Decision Sup 1semDB2 Databases 1sem… … …
Normal forms - 1NF, 2NF, 3NF
18
Concluding remarks
all definitions given were for relations with just 1CK any relation can be decomposed into a set of 3NF
relations 3NF is always achievable
are all non-loss decompositions equivalent? what happens in the case of relations with more than
1CK?