My Normalization Chapter
My Normalization Chapter
The logical
Two levels of relation "user view" level
Update Anomaly:
Changing the name of project number P1 from
“Billing” to “Customer-Accounting” may cause this update
to be made for all 100 employees working on project P1.
Insertion anomalies can be differentiated into two types,
illustrated by the following examples based on ….. The
EMP_DEPT relation :
CASE 1:
To insert a NEW EMP TUPLE into EMP_DEPT, we will have
EXAMPLE OF
to include the attribute value for the dept in which the
employee works, OR NULLs( if the EMP is currently not
allocated any DEPT )
AN INSERTION
ANOMALY (1) If the EMP is working in a DEPT ,then the DEPT data
(Dnum,Dname,Dmgr_ssn ) should be entered
CONSISTENTLY .
INSERTION
ANOMALY
(2)
On the Contrary…. If EMPLOYEE and DEPT are separate
tables then we do not have to worry about all this…. as DEPT is
a separate table in that scenario.
The problem of deletion anomalies is related to the SECOND
INSERTION ANOMALY SITUATION.
FDs and keys are used to define normal forms for relations
FDs are constraints that are derived from the meaning and
interrelationships of the data attributes
A.2
Practical The database designers need not normalize to the
highest possible normal form. (usually up to 3NF, BCNF
Use of or 4NF)
Normal
Forms Denormalization: the process of storing the join of
higher normal form relations as a base relation—
which is in a lower normal form
Definitions of Keys and Attributes
Participating in Keys (2)
Solution 1 :
Remove the attribute Dlocations that violate 1NF and place it in a separate
relation Dept_locations, along with the Primary key Dnumber.
Department
Dname Dnumber Dmgreno Dlocations
Among the 3 Solutions, the 1st solution is considered the best, because it
does not suffer from redundancy and is completely general.
The 1NF also does NOT allow attributes that are
composite
Now, it is in 1NF .
Figure 10.8 Normalization into 1NF
Second
Normal R can be decomposed into 2NF relations
via the process of 2NF normalization
Form …..
2NF Defination : A relation schema R is in 2 NF , if every non-prime
attribute A in R is fully functionally dependent on the Primary key of R.
Example :-
So the Next Step is to remove those attributes, which have Partial Functional Dependency
on the primary key.
2 NF Normalization
EP1
Eno Pno Hours
We see Full functional Dependency of every Non-prime attribute on the primary key .
(i.e ) to say that the Relation should NOT have a NON key
attribute
which is Functionally determined by another non key attribute .
Eno Ename
(P.K ) ( Non prime attribute )
Here Non prime attribute directly functionally dependent on P.K
Eno DOB
(P.K ) ( Non prime attribute )
Here Non prime attribute directly functionally dependent on P.K
Eno Address
(P.K ) ( Non prime attribute )
Here Non prime attribute directly functionally dependent on P.K
Eno Dnum
(P.K ) ( Non prime attribute )
Here Non prime attribute directly functionally dependent on P.K
Now left are Dname , and Dmgr_eno
Dname is not directly dependent on Eno (P.K)
Dname is Functionally dependent on Dnum.
As Dnum changes => Dname also changes
Dnum Dname
(Non Prime Attribute ) (Non Prime Attribute )
So, to get the relation in 3NF, we need to decompose the relation such
that we remove those Non-Prime attributes that are Functionally
Dependent on other Non-Prime attributes .
Decompose to get
Relation in 3NF
Now, in both the relations each of the Non-Prime attributes are F.D
on the Primary Key of that relation.
No non-prime attribute is F.D on another non-prime attribute.
No Transitive Dependency .
Normalizing into 2NF and 3NF
Zip street
Zip city
Zip state
Zip is a NON PRIME Attribute
Street, City and state are also NON PRIME Attributes.
So one Non Prime attribute is dependent on another NON PRIME ATTRIBUTE , which
in turn is dependent on the Primary Key (S_id).
Zip, Street , city, state are violating the 3NF , so remove them from the Table and put in another
Table .
FD 2 FD 3
FD 4
FD 1 is already in 2NF
In FD 2 we see …..
Staff_no Dentist_Name
It shows that Dentist_Name has PARTIAL FUNCTIONAL Dependency on Primary Key
( Staff_No, Appt_dt, Appt_time )
Dentist_Name Violates 2NF, so we remove it from the
Table )
In FD4 we see …..
(Staff_no , Appt_dt ) Surgery_ No
This shows that Surgery_No has PARTIAL FUNCTIONAL Dependency on Primary Key
( Staff_No, Appt_dt, Appt_time )
Surgery_No violates 2NF , hence remove it from the Table .
So, left in the Table are Patient_Name and Patient_No, along with the Primary
key .
FD1
FD4 Now in 2 NF
Dentist_name shifted to another Table .
Now we have obtained the above 3 Tables ( R1,R2, R3 )….which are in 2NF .
In table R1 ,
We see a NON Prime Attribute ( Patient_name) is FUNCTIONALLY Dependent on another
Non-Prime Attribute Patient_No.
And Patient_No is further Functionally Dependent on the Primary key.
So, Patient_Name is TRANSITIVELY dependent on the primary Key , through Patient_No.
So, PATIENT_NAME is VIOLATING 3NF .
So Put Patient_Name along with Patient_No in a separate
R 1A R 1B
Staff_no Appt_dt Appt_time Patient_no Patient_no Patient_Name
Now in 3 NF
We also observe that R2 and R3 are in 2 NF , aswell as 3 NF .
All three decompositions will lose fd1. We have to settle for sacrificing the
functional dependency preservation. But we cannot sacrifice the non-
additivity property after decomposition.
Out of the above three, only the 3rd decomposition will not generate spurious
tuples after join.(and hence has the non-additivity property).
A test to determine whether a binary decomposition (decomposition into two
relations) is nonadditive (lossless) is discussed in section 11.1.4 under
Property LJ1. Verify that the third decomposition above meets the property.
A.3 Definitions of Keys and Attributes
Participating in Keys (1)
SLIDE 34
SLIDE 22
Suppose we used Emp_Proj1 and Emp_Locs as
the base relations instead of EMP_PROJ (given
on slide 17 ).
This produces a bad schema design because
We cannot recover the information that was
Problem 4 originally in EMP_PROJ from EMP_PROJ1 and
EMP_LOCS.
1.4 Infact a NATURAL JOIN on these two relations,
Generation of produces many more erroneous tuples than the
original set .
Spurious These additional tuples that were not in
EMP_PROJ, are called SPURIOUS TUPLES.
Tuples They represent SPURIOUS INFORMATION that is
NOT VALID.
Emp_Proj1 Emp_Locs
1.4
GUIDELINE 4: To avoid generation of Spurious
Generation Tuples
of Spurious
Tuples The relations should be designed such that no
spurious tuples should be generated by doing a
natural-join of any relations.