You are on page 1of 35

NORMALIZATION

(3NF AND BCNF)


EXAMPLE
ANOMALIES

Insertion anomaly: if we want to insert the information of


a new salesperson, we cannot insert this information until
a customer is assigned to that person
Deletion anomaly: if we delete the only customer
assigned to a salesperson, we drop the information about
the salesperson
Update anomaly: if the region of a salesperson changes,
we have to search and find each customer assigned to
him.
CustID  Name
BUT
CustID  Salesperson
CustID  Region CustID  Salesperson  Region
Transitive dependency
(2nd NF)
TRANSITIVE DEPENDENCY

If an attribute is indirectly dependent on primary key,


then we say, there exists a transitive dependency.
For example:
If AB, BC then by transitivity theorem A C.
i.e. If A is the primary key, C is transitively dependent
on A and functionally dependent on B which is a
nonprime attribute.
THIRD NORMAL FORM

A relation r (R) is in third normal form (3NF) if and


only if the following conditions are satisfied
simultaneously.
1. R elation R is already in 2NF
2. No non-prime attribute is transitively dependent
on the key
or
No non-prime attribute functionally determines
any other non-prime attribute
THIRD NORMAL FORM (3NF)

1) Meet all the requirements of the 1NF


2) Meet all the requirements of the 2NF
3) Remove columns that are dependent upon the
non primary key.
DECOMPOSING THE SALES
RELATION
CustID  Name
CustID  Salesperson
EXAMPLE

Beer
Beer Brewery Strength City Region
Choice Websters XX York North West
Old Bob Websters XXX York North West
Landlord Taylors XXX Leeds North West
Directors Fremlins X London South East
Wobbly Joy Sam XXXX York North West
Smith
EXAMPLE..

functional dependencies
(beer, brewery, strength, city, region)
brewery  city
city  region
beer brewery, strength, city, region
Beer Brewery City
Beer Brewery Strength Websters York
Choice Webster's XX Taylors Leeds
Old Bob Webster's XXX Fremlins London
Landlord Taylors XXX Sam Smith York
Director Fremlins X
s
City Region
Wobbly Sam Smith XXXX
York North West
Leeds North West
London South East
EXERCISE

Sales order
(SalesOrderNo, Date, CustomerNo, CustomerName,
CustomerAdd, ClerkNo, ClerkName)
CERTIFICATION-PROGRAM table
(area, course, section, time, location)
ANOMALY

This relation is in 3NF because neither of the


nonprime attributes functionally determines the
other attributes.
However, if there is only one location per city
then Location  Area. If we delete the last tuple
of the relation we lose information about the
location of the educational center.
EXAMPLE

Student number Course Teacher


101 History Singh
101 Art Asha
102 Geography Aanchal
103 Sociology Smith
104 Economics Pradeep
105 History Singh
106 History Rekha
BOYCE-CODD NORMAL FORM

A relation r (R) is in Boyce-Codd form (BCNF) if


and only if the following conditions are met
simultaneously
1. The relation is in 1NF
2. For every functional dependency XA, we
have that either A X or X is a super key of r.
In other words, every functional dependency is
a trivial dependency or if it is not trivial
dependency then X must be a super key.
ALTERNATE DEFINITION

A relation is in BCNF if every determinant is a


candidate key.

A determinant is a column on which some of the


columns are fully functional dependent.
Student Teacher(pk)
number(pk) Teacher (pk) Course
101 Singh Singh History
101 Asha Asha Art
102 Aanchal Aanchal Geography
103 Smith Smith Sociology
104 Pradeep Pradeep Economics
105 Singh Rekha History
106 Rekha
EXAMPLE
SOLUTION

Set 1:
Manufacturer (id, name)
M-part (id, item-no, qty)
Set 2:
Manufacturer (id, name)
M-part (name, item-no, qty)
ClientInterview
Client interview interview
staffNo roomNo
No Date Time

CR76 13-May-02 10.30 SG5 G101

CR76 13-May-02 12.00 SG5 G101

CR74 13-May-02 12.00 SG37 G102

CR56 1-Jul-02 10.30 SG5 G102


FD1 clientNo, interviewDate  interviewTime, staffNo,
roomNo (Primary Key)
FD2 staffNo, interviewDate, interviewTime clientNo
(Candidate key)
FD3 roomNo, interviewDate, interviewTime  clientNo,
staffNo (Candidate key)
FD4 staffNo, interviewDate  roomNo (not a candidate
key) As a consequence the ClientInterview relation may suffer
from update anomalies. For example, two tuples have to be
updated if the roomNo need be changed for staffNo SG5 on the
13-May-02.
EXAMPLE

To transform the ClientInterview relation to BCNF, we must


remove the violating functional dependency by creating two
new relations called Interview and StaffRoom as shown
below

Interview (clientNo, interviewDate, interviewTime, staffNo)

StaffRoom(staffNo, interviewDate, roomNo)


BCNF Interview and StaffRoom relations
Interview
ClientNo interviewDate interviewTime staffNo
CR76 13-May-02 10.30 SG5
CR76 13-May-02 12.00 SG5
CR74 13-May-02 12.00 SG37
CR56 1-Jul-02 10.30 SG5

StaffRoom

staffNo interviewDate roomNo


SG5 13-May-02 G101
SG37 13-May-02 G102
SG5 1-Jul-02 G102
CONCURRENCY MANAGEMENT

Serializability Test
LOCKS

Read lock (shared locks): a transaction T wishing


only to read an item A executes RLOCK A which prevents
any other transaction from writing a new value of A while
T is reading A.
Write Lock (exclusive locks): a transaction wishing to
change the value of item A first obtains a write lock by
executing WLOCK A. when some transaction holds a write
lock on an item no other transaction can obtain a read
lock or write lock on that item.
Both locks can be removed using UNLOCK statement.
SERIALIZABILITY TEST FOR
SCHEDULES WITH READ/WRITE LOCKS

Input: a schedule S for a set of transactions T1, …Tk


Output: a determination whether S is serializable and if
so an equivalent serial schedule
Method: we construct a precedence graph G as follows
the nodes correspond to the transactions as before. The
arcs are determined by the following rules
1)Suppose in S transaction Ti, read locks A and Tj is the
next transaction to write lock A then place an arc from Ti
to Tj.
CONT..

2. Suppose in S, transaction Ti write locks A and Tj is the


next transaction to write lock A. then draw an arc Ti to
Tj. Further Tm be any transaction that reads locks A
after Ti unlocks its write lock but before Tj write locks
A. if there is no Tj, then Tm is any transaction to read
lock A after Ti unlocks A. then draw an arc Ti to Tm.

• If G has a cycle, then S is not serializable. If G is acyclic


then any topological sort of G is a serial order for the
transaction
1 WLOCK A
2 RLOCK B
3 UNLOCK A
4 RLOCK A
5 UNLOCK B
6 WLOCK B
7 RLOCK A
8 UNLOCK B
9 WLOCK B
10 UNLOCK A
11 UNLOCK A
12 WLOCK A
13 UNLOCK B
14 RLOCK B
15 UNLOCK A
16 UNLOCK B
T1 T2 T3 T4
GRAPH..

T1 T2

T4 T3
T17

T18

T19
SOLUTION

If G is acyclic, find a serial schedule as follows;


a.Initialize the serial schedule empty
b.Find a transaction Ti, such that there are no arcs
entering Ti. Ti is the next transaction in the serial schedule
c.Remove Ti and all edges emerging from it. If the
remaining set is empty, serial schedule is complete,
otherwise return to b
T17 T18 T19

You might also like