Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Normalization
1. Normalize the following Relationupto3rd
Normal form but stepby stpe, show
each intermediateresultant table withits data.
InvoiceID InvoiceDate CusID CusName ItemID ItemName ItemQty ItemPrice InvoiceTotal
601 11/9/18 C_101 Waqas 1 Scanner 50 10$ 2500$
601 2 Mouse 100 20$
602 11/9/18 C_101 3 Printer 40 10$ 400$
603 11/9/18 C_102 Saad 2 Mouse 50 20$ 1800$
603 4 Monitor 40 10$
603 1 Scanner 40 10$
It’s unnormalized table
In order to convert into First Normal Form(1NF)
1)Must be Atomic value in each cell
2)Identify attribute or attributes that qualifies as a
Primary Key
InvoiceID InvoiceDate CusID CusName ItemID ItemName ItemQty ItemPrice InvoiceTotal
601 11/9/18 C_101 Waqas 1 Scanner 50 10$ 2500$
601 11/9/18 C_101 Waqas 2 Mouse 100 20$ 2500$
602 11/9/18 C_101 Waqas 3 Printer 40 10$ 400$
603 11/9/18 C_102 Saad 2 Mouse 50 20$ 1800$
603 11/9/18 C_102 Saad 4 Monitor 40 10$ 1800$
603 11/9/18 C_102 Saad 1 Scanner 40 10$ 1800$
Primary Key of given table consists three attributes
(InvoiceID,CusID,ItemID)
It’s a composite key
Draw lines in these attributes
2. Analysis of relationship by looking its Records(Rows)
1) One invoiceID has only one same customerID ( 601 has C_101, 602 has
C_101 and 603 has C_102). It’s one to one relationship.
2) One invoiceID has many items (601 has ItemID 1 and 2). It’s one to many
relationship.
3) One customer has many items (C_101 has itemID 1,2 and 3). It’s one to
many relationship.
In order to convert into second Normal Form(2NF)
1)It’s in 1NF
2) No partial dependency
Partial Dependency: Non-key attributes depend on
a part of Primary key.
Non-Key attribute: The atttibute or set of attributes
that cannot be qualified as a Primarykey (Which can
not be used to identify a record uniquely.
Here, InvoiceID,CusID and ItemID is a part of
primary key.
3. List out Non-key attributes: InvoiceDate,
InvoiceTotal, CusName, ItemName, ItemQty and
ItemPrice
InvoiceDate and InvoiceTotal are depend
on a part of primary key (InvoiceID). It
must be fully dependent on InvoiceID (not
a part of primary key).
CusName is dependent on a part of primary
key (CusID). It must be fully dependent on
CusID (not a part of primary key).
ItemName, ItemQty and ItemPrice are
dependent on a part of primary key (ItemID). It
must be fully dependent on ItemID (not a part
of primary key).
InvoiceID InvoiceDate InvoiceTotal
601 11/9/18 2500$
602 11/9/18 400$
603 11/9/18 1800$
Invoice
Now InvoiceDate and InvoiceTotal are dependent onprimary key.
CusID CusName
C_101 Waqas
C_102 Saad
Customer
4. Now CusName is dependent on primary key.
It’s incorrect relation(Table). How??????
ItemID ItemName ItemQty ItemPrice
1 Scanner 50 10$
2 Mouse 100 20$
3 Printer 40 10$
4 Monitor 40 10$
Oh!!!!!!!! NO
Are you noticed that we have lost some data?
=>Let check it, in 1NF relation
ItemID 1 has ItemQty 50 of CusID C_101
And ItemID 1 has ItemQty 40 of CusID C_102.
In this way, we have lost record of CusID C_102 about its
itemQty 40.
ItemID ItemName ItemPrice
1 Scanner 10$
2 Mouse 20$
3 Printer 10$
4 Monitor 10$
Item
CusID ItemID ItemQty
C_101 1 50
C_101 2 100
C_101 3 40
C_102 2 50
5. C_102 4 40
C_102 1 40
Customer_Item
Customer_Itemis satisfied the relationship3.
InvoiceID ItemID
601 1
601 2
602 3
603 2
603 4
603 1
Invoice_Item
Invoice_Itemis satisfiedrelationship2.
We have done our relationshipsdata analysis
All relations(Tables)Customer, Item, Invoice,
Invoice_Item and Customer_Item are in 2NF.
Now, we are moving to convert into third Normal
Form(3NF).
1) It’s in 2NF
2) No transitive dependency
Transitive Dependency: Non key attributes depend on
another non-key attributes.