SlideShare a Scribd company logo
Rushdi Shams, Dept of CSE, KUET 1
Database SystemsDatabase Systems
Normal FormsNormal Forms
Version 1.0Version 1.0
2Rushdi Shams, Dept of CSE, KUET
NormalizationNormalization
 ItIt avoids duplication of dataavoids duplication of data. Hence it is a. Hence it is a tool totool to
avoid redundancy of dataavoid redundancy of data..
 Theorists gave loads of “do this”, “do that” thing whenTheorists gave loads of “do this”, “do that” thing when
relational model was first invoked. One of those wererelational model was first invoked. One of those were
normal forms. Applying those theories on databases arenormal forms. Applying those theories on databases are
called normalizatoin.called normalizatoin.
 But the fact is,But the fact is, in commercial environment, loads ofin commercial environment, loads of
works are done by not maintaining theworks are done by not maintaining the
normalization theories 100%!normalization theories 100%!
3Rushdi Shams, Dept of CSE, KUET
Why Normalization?Why Normalization?
4Rushdi Shams, Dept of CSE, KUET
Why Normalization? (continued)Why Normalization? (continued)
 What if we want to delete the student no 34668?What if we want to delete the student no 34668?
Alas! We will lose information about DEDUCTIVEAlas! We will lose information about DEDUCTIVE
DATABASE, its lecturer name and many more!DATABASE, its lecturer name and many more!
 What if we want to update the lecturer to NICKWhat if we want to update the lecturer to NICK
WHITTAKER? We will have to put staff name as wellWHITTAKER? We will have to put staff name as well
as staff no for that!as staff no for that!
 What if we want to insert a new student with numberWhat if we want to insert a new student with number
38989? We cannot insert any student who does not38989? We cannot insert any student who does not
have any assessment criteria!have any assessment criteria!
5Rushdi Shams, Dept of CSE, KUET
AnomaliesAnomalies
 An anomaly is a bad thing. Because it tends theAn anomaly is a bad thing. Because it tends the
data in a database LOGICALLY getdata in a database LOGICALLY get
corrupted!corrupted!
 There are mainly 3 types of anomaliesThere are mainly 3 types of anomalies
1.1. Insert anomalyInsert anomaly
2.2. Delete anomalyDelete anomaly
3.3. Update anomalyUpdate anomaly
The reason why I switched to discuss aboutThe reason why I switched to discuss about
anomaly- you will understand later!anomaly- you will understand later!
6Rushdi Shams, Dept of CSE, KUET
Insert AnomalyInsert Anomaly
 It is caused when an insertion takes place in aIt is caused when an insertion takes place in a
child table, where there is no record in thechild table, where there is no record in the
parent table!parent table!
7Rushdi Shams, Dept of CSE, KUET
Insert Anomaly (continued)Insert Anomaly (continued)
 What if you try to insertWhat if you try to insert
a book of J K Rawlingsa book of J K Rawlings
into the table left withoutinto the table left without
putting her name into theputting her name into the
table below?table below?
8Rushdi Shams, Dept of CSE, KUET
Delete AnomalyDelete Anomaly
 Caused when a data in the parent table is deletedCaused when a data in the parent table is deleted
before deleting all the related data from its childbefore deleting all the related data from its child
(ren) table(s).(ren) table(s).
 Well, if you prefer a cascaded deletion, no oneWell, if you prefer a cascaded deletion, no one
would mind!would mind!
9Rushdi Shams, Dept of CSE, KUET
Delete Anomaly (continued)Delete Anomaly (continued)
 Before deleting the dataBefore deleting the data
from the table below, iffrom the table below, if
you delete data fromyou delete data from
table in right, what dotable in right, what do
you think it is gonnayou think it is gonna
happen?happen?
10Rushdi Shams, Dept of CSE, KUET
Update AnomalyUpdate Anomaly
 It is kind of like delete anomaly. Both the parentIt is kind of like delete anomaly. Both the parent
table and child(ren) table(s) should get updatedtable and child(ren) table(s) should get updated
concurrently!concurrently!
11Rushdi Shams, Dept of CSE, KUET
More JargonsMore Jargons
 Well, before starting with normalizations, youWell, before starting with normalizations, you
must need to know some jargons. You alreadymust need to know some jargons. You already
are aware of anomalies. Let’s get into someare aware of anomalies. Let’s get into some
more!more!
12Rushdi Shams, Dept of CSE, KUET
Functional DependencyFunctional Dependency
 Y is functionally dependent on X if the values ofY is functionally dependent on X if the values of
Y are determined by the values of X.Y are determined by the values of X.
 Y=X+1. In this case, Y is functionallyY=X+1. In this case, Y is functionally
dependent on Xdependent on X
 y=f(x). In this generic case, y is functionallyy=f(x). In this generic case, y is functionally
dependent on x as well.dependent on x as well.
13Rushdi Shams, Dept of CSE, KUET
Functional Dependency (continued)Functional Dependency (continued)
 In this case, CURRENCY is functionallyIn this case, CURRENCY is functionally
dependent on FXCODEdependent on FXCODE
14Rushdi Shams, Dept of CSE, KUET
DeterminantDeterminant
 If X determines the values of Y, then X will beIf X determines the values of Y, then X will be
called the determinant of Ycalled the determinant of Y
 Y=X+1. In this case, X is determinant of Y.Y=X+1. In this case, X is determinant of Y.
 y=f(x). In this case, x is determinant of y as well.y=f(x). In this case, x is determinant of y as well.
15Rushdi Shams, Dept of CSE, KUET
Determinant (continued)Determinant (continued)
 In this case, FXCODE is determinant ofIn this case, FXCODE is determinant of
CURRENCY.CURRENCY.
16Rushdi Shams, Dept of CSE, KUET
Transitive DependencyTransitive Dependency
 If the value of Z is determined by Y and theIf the value of Z is determined by Y and the
value of Y is determined by X, then there is avalue of Y is determined by X, then there is a
transitive dependency between X and Z.transitive dependency between X and Z.
 This dependency thus states the indirectThis dependency thus states the indirect
dependency.dependency.
BackBack
17Rushdi Shams, Dept of CSE, KUET
Transitive Dependency (continued)Transitive Dependency (continued)
 In this case, RATE is dependent onIn this case, RATE is dependent on
CURRENCY. CURRENCY is dependent onCURRENCY. CURRENCY is dependent on
COUNTRY. So, RATE is transitively dependentCOUNTRY. So, RATE is transitively dependent
on COUNTRY.on COUNTRY.
18Rushdi Shams, Dept of CSE, KUET
Candidate keyCandidate key
 It is theIt is the minimal setminimal set of super key.of super key.
 Say, from this example, you only can have super keysSay, from this example, you only can have super keys
as followings (though you may have otheras followings (though you may have other
combinations, but just shorten that this time)-combinations, but just shorten that this time)-
{roll, name}, {roll, name, dept}, {roll, name, year,{roll, name}, {roll, name, dept}, {roll, name, year,
semester}semester}
In this case, the candidate key is {roll, name}!In this case, the candidate key is {roll, name}!
RollRoll NameName DeptDept YearYear SemestSemest
erer
19Rushdi Shams, Dept of CSE, KUET
Full Functional DependencyFull Functional Dependency
 If X determines Y but X with combination of ZIf X determines Y but X with combination of Z
does not determine Y- then, there is a fulldoes not determine Y- then, there is a full
functional dependency between X and Y.functional dependency between X and Y.
 So, X cannot be a composite key.So, X cannot be a composite key.
Nb. If you make a key with 2 or more columns,Nb. If you make a key with 2 or more columns,
then that is called a composite key.then that is called a composite key.
20Rushdi Shams, Dept of CSE, KUET
Full Functional DependencyFull Functional Dependency
(continued)(continued)
 In this case,In this case,
POPULATION dependsPOPULATION depends
on COUNTRY not onon COUNTRY not on
the combination ofthe combination of
RATE andRATE and
COUNTRY. So,COUNTRY. So,
POPULATION is fullyPOPULATION is fully
functional dependent onfunctional dependent on
COUNTRY and also youCOUNTRY and also you
can say that,can say that,
POPULATION is notPOPULATION is not
fully functionalfully functional
dependent on RATE anddependent on RATE and
COUNTRY!COUNTRY!
21Rushdi Shams, Dept of CSE, KUET
11stst
Normal Form: 1NFNormal Form: 1NF
 Academic Definitions:Academic Definitions:
1. Eliminate repeating groups such that all
records in all tables can be identified uniquely
by a primary key in each table. In other words,
all fields other than the primary key must
depend on the primary key.
2. A relation is in first normal form if and only if
every non-key attribute is functionally
dependent upon the primary key
22Rushdi Shams, Dept of CSE, KUET
1 NF (continued)1 NF (continued)
3. A relation is in first normal form if the
domains on which its attributes are defined are
scalar
BackBack
23Rushdi Shams, Dept of CSE, KUET
1 NF (continued)1 NF (continued)
 Easy Definition:Easy Definition:
1 NF is a process of removing repeating groups1 NF is a process of removing repeating groups
from a table by creating a new tablefrom a table by creating a new table
They are linked by a one to many relationshipThey are linked by a one to many relationship
Create primary keys on both tablesCreate primary keys on both tables
The child table will have a composite primaryThe child table will have a composite primary
key (one of its own, other is its foreign key fromkey (one of its own, other is its foreign key from
its parent table)its parent table)
24Rushdi Shams, Dept of CSE, KUET
What does 1 NF do?What does 1 NF do?
 Academic Way:Academic Way:
 Eliminates repeating groupsEliminates repeating groups
 Defines primary keysDefines primary keys
 No duplicate entry allowedNo duplicate entry allowed
 All fields other than primary key depend on primaryAll fields other than primary key depend on primary
keykey
 All columns must contain a single value (seeAll columns must contain a single value (see
Definition 3Definition 3))
 All values in a column must have the same data typeAll values in a column must have the same data type
 Create a table to move repeating data from the currentCreate a table to move repeating data from the current
tabletable
25Rushdi Shams, Dept of CSE, KUET
Not Scalar- Not 1 NFNot Scalar- Not 1 NF
26Rushdi Shams, Dept of CSE, KUET
Repeating Groups- Not 1 NFRepeating Groups- Not 1 NF
27Rushdi Shams, Dept of CSE, KUET
0 NF to 1 NF0 NF to 1 NF
 Remove repeatingRemove repeating
groups. Split table intogroups. Split table into
tables with one to manytables with one to many
relationship.relationship.
28Rushdi Shams, Dept of CSE, KUET
0 NF to 1 NF (continued)0 NF to 1 NF (continued)
 Creating primary key onCreating primary key on
parent table andparent table and
composite primary keycomposite primary key
on child table (where iton child table (where it
has a foreign keyhas a foreign key
referenced to parentreferenced to parent
table)table)
29Rushdi Shams, Dept of CSE, KUET
Our 1 NFOur 1 NF
30Rushdi Shams, Dept of CSE, KUET
Can you do it?Can you do it?
31Rushdi Shams, Dept of CSE, KUET
Yes! You Can!!Yes! You Can!!
32Rushdi Shams, Dept of CSE, KUET
Second Normal Form- 2 NFSecond Normal Form- 2 NF
 Academic Definition:Academic Definition:
1. A relation is in second normal form if and only
if it is in first normal form and every non-key
attribute is fully functionally dependent on the
primary key
2.2. A relation is in second normal form ifA relation is in second normal form if it is init is in
first normal formfirst normal form and, in addition,and, in addition, all itsall its
attributes are dependent on the entireattributes are dependent on the entire
candidate keycandidate key
33Rushdi Shams, Dept of CSE, KUET
What does 2 NF do?What does 2 NF do?
 Academic Way:Academic Way:
 The table is in 1 NFThe table is in 1 NF
 All non-key values must be functionally dependent on
the primary key. In other words, non-key fields not
dependent on the primary key are not allowed.
 Partial dependencies must be removed. A partial
dependency is a special type of functional dependency
that exists when a field is dependant on a part of a
composite primary key.
 Create a table with partially dependent part of the
primary key and its dependents.
34Rushdi Shams, Dept of CSE, KUET
Which is not 2 NF?Which is not 2 NF?
Solution!Solution!
35Rushdi Shams, Dept of CSE, KUET
1 NF to 2 NF1 NF to 2 NF
36Rushdi Shams, Dept of CSE, KUET
Separating TablesSeparating Tables
37Rushdi Shams, Dept of CSE, KUET
Providing Many to One RelationProviding Many to One Relation
38Rushdi Shams, Dept of CSE, KUET
Providing One to Many RelationshipProviding One to Many Relationship
39Rushdi Shams, Dept of CSE, KUET
Can You Do It?Can You Do It?
40Rushdi Shams, Dept of CSE, KUET
Yes! You Can!!Yes! You Can!!
41Rushdi Shams, Dept of CSE, KUET
Remember Me? I was not 2 NF!!Remember Me? I was not 2 NF!!
See Me!See Me!
42Rushdi Shams, Dept of CSE, KUET
33rdrd
Normal Form- 3 NFNormal Form- 3 NF
 Academic Way:Academic Way:
 The table must be in 2 NFThe table must be in 2 NF
 Eliminate transitive dependency (Eliminate transitive dependency (
see Transitive Dependencysee Transitive Dependency))
 Create a new table to contain any separatedCreate a new table to contain any separated
columnscolumns
43Rushdi Shams, Dept of CSE, KUET
3 NF3 NF
 Easy Way:Easy Way:
 Meet the requirements by 1 NF and 2 NFMeet the requirements by 1 NF and 2 NF
 Remove columns that are not fully dependentRemove columns that are not fully dependent
on the primary keyon the primary key
44Rushdi Shams, Dept of CSE, KUET
3 NF (case study)3 NF (case study)
 Imagine we have a table that contains theImagine we have a table that contains the
following columns-following columns-
1.1. Order numberOrder number
2.2. Customer numberCustomer number
3.3. Unit priceUnit price
4.4. QuantityQuantity
5.5. TotalTotal
45Rushdi Shams, Dept of CSE, KUET
3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in
1 NF1 NF
1.1. Order numberOrder number
2.2. Customer numberCustomer number
3.3. Unit priceUnit price
4.4. QuantityQuantity
5.5. TotalTotal
 Are there duplicate columns? No!Are there duplicate columns? No!
 Do we have a primary key? Yes, the order number!Do we have a primary key? Yes, the order number!
 Fine, it is in 1 NF then!!Fine, it is in 1 NF then!!
46Rushdi Shams, Dept of CSE, KUET
3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in
2 NF2 NF
1.1. Order numberOrder number
2.2. Customer numberCustomer number
3.3. Unit priceUnit price
4.4. QuantityQuantity
5.5. TotalTotal
 Are there any static of data that apply toAre there any static of data that apply to
multiple rows? No!multiple rows? No!
 Fine, we are in 2 NF then!!Fine, we are in 2 NF then!!
47Rushdi Shams, Dept of CSE, KUET
3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in
3 NF3 NF
1.1. Order numberOrder number
2.2. Customer numberCustomer number
3.3. Unit priceUnit price
4.4. QuantityQuantity
5.5. TotalTotal
 Are all of the columns fully depend on theAre all of the columns fully depend on the
primary key (order number)?primary key (order number)?
48Rushdi Shams, Dept of CSE, KUET
3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in
3 NF (continued)3 NF (continued)
 The customer number varies with the order numberThe customer number varies with the order number
and it doesn't appear to depend upon any of the otherand it doesn't appear to depend upon any of the other
fieldsfields
 What about the unit price? This field could beWhat about the unit price? This field could be
dependent upon the customer number in a situationdependent upon the customer number in a situation
where we charged each customer a set price. However,where we charged each customer a set price. However,
looking at the data above, it appears we sometimeslooking at the data above, it appears we sometimes
charge the same customer different prices. Therefore,charge the same customer different prices. Therefore,
the unit price is fully dependent upon the order numberthe unit price is fully dependent upon the order number
49Rushdi Shams, Dept of CSE, KUET
3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in
3 NF (continued)3 NF (continued)
 The quantity of items also varies from order toThe quantity of items also varies from order to
order, so we're OK there.order, so we're OK there.
 What about the total? It looks like we might beWhat about the total? It looks like we might be
in trouble here. The total can be derived byin trouble here. The total can be derived by
multiplying the unit price by the quantity,multiplying the unit price by the quantity,
therefore it's not fully dependent upon thetherefore it's not fully dependent upon the
primary key. We must remove it from the tableprimary key. We must remove it from the table
to comply with the third normal form.to comply with the third normal form.
50Rushdi Shams, Dept of CSE, KUET
3 NF (case study): Making it a 3 NF3 NF (case study): Making it a 3 NF
1.1. Order numberOrder number
2.2. Customer numberCustomer number
3.3. Unit priceUnit price
4.4. QuantityQuantity
 Now, the table is in 3 NF. What about total?Now, the table is in 3 NF. What about total?
Well, there is no need to put it on a separateWell, there is no need to put it on a separate
table! You can make a select command to grabtable! You can make a select command to grab
the total by multiplying unit price withthe total by multiplying unit price with
quantity- can’t you?quantity- can’t you?
51Rushdi Shams, Dept of CSE, KUET
3 NF3 NF
 Did you see theDid you see the
irrelevant columns in theirrelevant columns in the
2 tables?2 tables?
 You need to separateYou need to separate
them!them!
52Rushdi Shams, Dept of CSE, KUET
3 NF (continued)3 NF (continued)
 Eliminated the irrelevantEliminated the irrelevant
columns and makingcolumns and making
them a separate table.them a separate table.
53Rushdi Shams, Dept of CSE, KUET
3 NF (continued)3 NF (continued)
 Can you see theCan you see the
irrelevant column here?irrelevant column here?
 You need to separateYou need to separate
them to make it a 3 NF!them to make it a 3 NF!
54Rushdi Shams, Dept of CSE, KUET
3 NF (continued)3 NF (continued)
55Rushdi Shams, Dept of CSE, KUET
3 NF (continued)3 NF (continued)
 Did you see the columnDid you see the column
that does not depend onthat does not depend on
the primary key?the primary key?
 You need to separateYou need to separate
that column from thethat column from the
table to make it 3 NFtable to make it 3 NF
56Rushdi Shams, Dept of CSE, KUET
3 NF (continued)3 NF (continued)
57Rushdi Shams, Dept of CSE, KUET
Can you do it?Can you do it?
58Rushdi Shams, Dept of CSE, KUET
Yes! You Can!!Yes! You Can!!
59Rushdi Shams, Dept of CSE, KUET
Be warned!Be warned!
 3 NF is said to be the most crucial and most3 NF is said to be the most crucial and most
ambiguous, most complex part of normalization!ambiguous, most complex part of normalization!
60Rushdi Shams, Dept of CSE, KUET
Bad thing of too much normalizationBad thing of too much normalization
 Did you take a look at the number of tableDid you take a look at the number of table
increased from 0 NF to 3 NF? If it is a bigincreased from 0 NF to 3 NF? If it is a big
enterprise database, then can you imagine howenterprise database, then can you imagine how
far this can go?far this can go?
 Too many tables lead us to too many joinsToo many tables lead us to too many joins
 Joins are one of the complex codings and timeJoins are one of the complex codings and time
consuming subtle entities in database systemsconsuming subtle entities in database systems
 So, try to normalize, but don’t normalize in aSo, try to normalize, but don’t normalize in a
way that you have 1000 tables!way that you have 1000 tables!
61Rushdi Shams, Dept of CSE, KUET
Beyond 3 NFBeyond 3 NF
 Most software development firms dealing withMost software development firms dealing with
database systems do not go beyond 3 NF anddatabase systems do not go beyond 3 NF and
many of them even try not to reach 3 NF!!many of them even try not to reach 3 NF!!
62Rushdi Shams, Dept of CSE, KUET
Boyce Codd Normal Form (BCNF)Boyce Codd Normal Form (BCNF)
 It is a variation of 3 NFIt is a variation of 3 NF
 In a 3NF table, all attributes are dependent on a key, aIn a 3NF table, all attributes are dependent on a key, a
whole key and nothing but a keywhole key and nothing but a key
 A table is said to be in BCNF if and only if it is in 3NFA table is said to be in BCNF if and only if it is in 3NF
and every non-trivial, left-irreducible functionaland every non-trivial, left-irreducible functional
dependency has a candidate key as its determinantdependency has a candidate key as its determinant
 In more informal terms, a table is in BCNF if it is inIn more informal terms, a table is in BCNF if it is in
3NF and the only determinants are the candidate keys3NF and the only determinants are the candidate keys
63Rushdi Shams, Dept of CSE, KUET
BCNF (continued)BCNF (continued)
64Rushdi Shams, Dept of CSE, KUET
BCNF (continued)BCNF (continued)
 Primary key is product category and productPrimary key is product category and product
subcategorysubcategory
 The table is in 3NF, for each of its non-key attributes isThe table is in 3NF, for each of its non-key attributes is
non-transitively dependent on the full key (Productnon-transitively dependent on the full key (Product
Category, Product Subcategory).Category, Product Subcategory).
65Rushdi Shams, Dept of CSE, KUET
BCNF (continued)BCNF (continued)
 Yet the table has redundant data. Look at column 1,Yet the table has redundant data. Look at column 1,
column 3 and column 4 for the last 4 rows!column 3 and column 4 for the last 4 rows!
66Rushdi Shams, Dept of CSE, KUET
BCNF (continued)BCNF (continued)
 Indeed, Range Code is dictated by the combination of ProductIndeed, Range Code is dictated by the combination of Product
Category and Stock CategoryCategory and Stock Category
 Is stock category a candidate key? NO! Then it is not in BCNF!!Is stock category a candidate key? NO! Then it is not in BCNF!!
67Rushdi Shams, Dept of CSE, KUET
BCNF (continued)BCNF (continued)
 The point about BCNF is that a candidate key is, by
definition, a unique key, and thus a potential primary
key.
 If a table contains more than one candidate key
(primary key), it has a problem according to BCNF. I
disagree!
 BCNF divides a table up into multiple tables to ensure
that no single table has more than one potential primary
key
 BCNF prohibits a table from having two possible
primary keys.
68Rushdi Shams, Dept of CSE, KUET
Anomaly problemAnomaly problem
 In this table, say, studentNo and Area is primary keyIn this table, say, studentNo and Area is primary key
69Rushdi Shams, Dept of CSE, KUET
Anomaly problemAnomaly problem
 What if 123456 wants to change her subject toWhat if 123456 wants to change her subject to
information systems? We will lose the data-information systems? We will lose the data-
who is taking the course computer science?who is taking the course computer science?
 This is update anomalyThis is update anomaly
70Rushdi Shams, Dept of CSE, KUET
Anomaly problemAnomaly problem
 What if staff 250 also will take computer science? IfWhat if staff 250 also will take computer science? If
there is no student enrolled in that subject, then wethere is no student enrolled in that subject, then we
cannot insert that information in this table!!cannot insert that information in this table!!
 This is insert anomalyThis is insert anomaly
71Rushdi Shams, Dept of CSE, KUET
Anomaly problemAnomaly problem
 What if 123456 wants to withdraw from the courseWhat if 123456 wants to withdraw from the course
Software Engineering? We will lose the data-Software Engineering? We will lose the data-
Who will take the course Software Engineering!!Who will take the course Software Engineering!!
 This is delete anomalyThis is delete anomaly
72Rushdi Shams, Dept of CSE, KUET
Why anomaly?Why anomaly?
 The anomalies occurred because, there are twoThe anomalies occurred because, there are two
overlapping candidate keys- student number andoverlapping candidate keys- student number and
area!area!
73Rushdi Shams, Dept of CSE, KUET
Normalizing to BCNFNormalizing to BCNF
 Suppose a relation R is not inSuppose a relation R is not in BCNFBCNF. Then there must be some. Then there must be some
functional dependency X → A where X is not a superkey.functional dependency X → A where X is not a superkey.
 In this case, the relation can be decomposed into the twoIn this case, the relation can be decomposed into the two
relationsrelations
1.1. R1= R − AR1= R − A
2.2. R2= XAR2= XA
 where R − A simply means dropping the attribute A from thewhere R − A simply means dropping the attribute A from the
schema and XA is the relation whose attributes are those in Xschema and XA is the relation whose attributes are those in X
together with Atogether with A
 Then examine the new tables if you can apply 1 and 2 on themThen examine the new tables if you can apply 1 and 2 on them
again!again!
 When you cannot apply 1 and 2 on them, then it’s in BCNF!!When you cannot apply 1 and 2 on them, then it’s in BCNF!!
74Rushdi Shams, Dept of CSE, KUET
BCNF ExampleBCNF Example
 Product category+stock category determines range code.Product category+stock category determines range code.
 So, make two tables.So, make two tables.
1.1. Product category, product subcategory, stock category, rangeProduct category, product subcategory, stock category, range
subcodesubcode
2.2. Product category, stock category, range codeProduct category, stock category, range code
75Rushdi Shams, Dept of CSE, KUET
BCNF example (continued)BCNF example (continued)
76Rushdi Shams, Dept of CSE, KUET
BCNF example (continued)BCNF example (continued)
 Now, observe this new table. In it, the range subcodeNow, observe this new table. In it, the range subcode
depends on stock category and product subcategory.depends on stock category and product subcategory.
So, make two tables.So, make two tables.
1.1. Product category, product subcategory, stock categoryProduct category, product subcategory, stock category
2.2. Product subcategory, stock category, range subcodeProduct subcategory, stock category, range subcode
77Rushdi Shams, Dept of CSE, KUET
BCNF example (continued)BCNF example (continued)
78Rushdi Shams, Dept of CSE, KUET
Our tables in BCNFOur tables in BCNF
79Rushdi Shams, Dept of CSE, KUET
Fourth Normal Form (4 NF)Fourth Normal Form (4 NF)
 A table must be in 3 NF or BCNF with 3 NFA table must be in 3 NF or BCNF with 3 NF
 Multi-valued dependencies must be transformed into functional
dependencies. This implies that one value and not multiple
values are dependent on a primary key.
 Eliminate multiple sets of multiple valued or multi-valued
dependencies, sometimes described as non-trivial multi-valued
dependencies.
 NF and has no multiple sets of multi-valued dependencies. In
other words, 4NF states that no entity can have more than a
single one-to-many relationship within an entity if the one-to-
many attributes are independent of each other.
80Rushdi Shams, Dept of CSE, KUET
4 NF Example4 NF Example
 In this table, there are 3In this table, there are 3
columns. Employee, skillcolumns. Employee, skill
and skilllanguageand skilllanguage
 Employee is the primaryEmployee is the primary
keykey
 The table is in BCNFThe table is in BCNF
with 3NFwith 3NF
81Rushdi Shams, Dept of CSE, KUET
4 NF Example4 NF Example
 The record for employeeThe record for employee
number 0122443 can benumber 0122443 can be
written also in the form-written also in the form-
0122443: Typing,0122443: Typing,
Dictation: English,Dictation: English,
French in the formFrench in the form
employee: skill:employee: skill:
skilllanguageskilllanguage
82Rushdi Shams, Dept of CSE, KUET
4 NF Example4 NF Example
 So, the multivaluedSo, the multivalued
dependency is on skilldependency is on skill
column and skilllanguagecolumn and skilllanguage
column!column!
 To make it in 4 NF, youTo make it in 4 NF, you
will have to simply splitwill have to simply split
them into separate table,them into separate table,
nothing else!!nothing else!!
83Rushdi Shams, Dept of CSE, KUET
4 NF Example4 NF Example
84Rushdi Shams, Dept of CSE, KUET
Solving one, creates anotherSolving one, creates another
problem!problem!
 Can you say, what is the problem still with theCan you say, what is the problem still with the
tables?tables?
 There are still 2 entries for the same employee!!There are still 2 entries for the same employee!!
85Rushdi Shams, Dept of CSE, KUET
Fifth Normal Form (5 NF)Fifth Normal Form (5 NF)
 Personally, I really hate this form!!Personally, I really hate this form!!
 The table must have to be in 4 NF (same oldThe table must have to be in 4 NF (same old
dialogue!)dialogue!)
 The table should not contain any cyclicThe table should not contain any cyclic
dependency!dependency!
 Cyclic dependency is like say your table has 3Cyclic dependency is like say your table has 3
columns. Column 1 depends on 2, 2 on 3 and 3columns. Column 1 depends on 2, 2 on 3 and 3
on 1!!on 1!!
 Also known as PJNF (Projection Normal Form)Also known as PJNF (Projection Normal Form)
86Rushdi Shams, Dept of CSE, KUET
5 NF (continued)5 NF (continued)
 Try begin with creating a table EmployeesTry begin with creating a table Employees
 All the 3 columns are primary key (kind of weird, isn’tAll the 3 columns are primary key (kind of weird, isn’t
it?? We can call it composite primary key)it?? We can call it composite primary key)
87Rushdi Shams, Dept of CSE, KUET
5 NF (continued)5 NF (continued)
 Let’s insert some data in Employees table then.Let’s insert some data in Employees table then.
88Rushdi Shams, Dept of CSE, KUET
5 NF (continued)5 NF (continued)
 Employees table now look like this!Employees table now look like this!
 There is no multivalued dependency, so, the table is inThere is no multivalued dependency, so, the table is in
4 NF (of course also in 1-2-3-BC NF!!)4 NF (of course also in 1-2-3-BC NF!!)
89Rushdi Shams, Dept of CSE, KUET
5 NF (continued)5 NF (continued)
 Now, let’s play with the basic table Employees. We willNow, let’s play with the basic table Employees. We will
split the table into three tables. WHY? I will say yousplit the table into three tables. WHY? I will say you
later.later.
 We are making three tables- project_employee,We are making three tables- project_employee,
project_manager, manager_employeeproject_manager, manager_employee
90Rushdi Shams, Dept of CSE, KUET
Detail of project_employeeDetail of project_employee
91Rushdi Shams, Dept of CSE, KUET
Detail of project_managerDetail of project_manager
92Rushdi Shams, Dept of CSE, KUET
Detail of manager_employeeDetail of manager_employee
93Rushdi Shams, Dept of CSE, KUET
The Fun!The Fun!
 Now, we will query the initial table Employees! It will show usNow, we will query the initial table Employees! It will show us
the whole tablethe whole table
94Rushdi Shams, Dept of CSE, KUET
The Fun Continues!The Fun Continues!
 Now, we will join the three new tables and will get theNow, we will join the three new tables and will get the
same answer!!same answer!!
95Rushdi Shams, Dept of CSE, KUET
So, what is the fun for?So, what is the fun for?
 The fun is, if you have a table in 4 NF but withThe fun is, if you have a table in 4 NF but with
cyclic dependency, if you can split it into xcyclic dependency, if you can split it into x
number of tables and then while joining those xnumber of tables and then while joining those x
number of tables, it will give you back the initialnumber of tables, it will give you back the initial
table, you then made it 5 NF while splitting!table, you then made it 5 NF while splitting!
 Phew!!Phew!!
96Rushdi Shams, Dept of CSE, KUET
Domain Key Normal Form (DKNF)Domain Key Normal Form (DKNF)
 Please god, help us! There are loads of normalPlease god, help us! There are loads of normal
forms! I cannot go beyond that! Well, folks, thisforms! I cannot go beyond that! Well, folks, this
one is the last- I promise!!one is the last- I promise!!
 Domain/key normal form (DKNF) is a normalDomain/key normal form (DKNF) is a normal
used in database normalization which requiresused in database normalization which requires
that the database contains no constraints otherthat the database contains no constraints other
than domain constraints and key constraints.than domain constraints and key constraints.
97Rushdi Shams, Dept of CSE, KUET
DKNF (continued)DKNF (continued)
 This table violates the rules for being DKNFThis table violates the rules for being DKNF
 If Wealthy person type is Eccentric Millionaire/ evil millionaire,If Wealthy person type is Eccentric Millionaire/ evil millionaire,
then the Net Worth in Dollars must be 1,000,000 to 999,999,999then the Net Worth in Dollars must be 1,000,000 to 999,999,999
inclusive and if that is Evil Billionaire/ Eccentric Billionaire, theninclusive and if that is Evil Billionaire/ Eccentric Billionaire, then
it should be 1,000,000,000 or higher.it should be 1,000,000,000 or higher.
98Rushdi Shams, Dept of CSE, KUET
So, what to do?So, what to do?
 Nothing serious, the violation on domain can be solvedNothing serious, the violation on domain can be solved
easily by changing the domain of Wealthy Person Typeeasily by changing the domain of Wealthy Person Type
to Eccentric and Evil- forget about Millionaire andto Eccentric and Evil- forget about Millionaire and
Billionaire!!Billionaire!!
 It is then in DKNF!!It is then in DKNF!!
99Rushdi Shams, Dept of CSE, KUET
The Flow chartThe Flow chart
 Say, you are given a table in 0 NF. Do theSay, you are given a table in 0 NF. Do the
followings one by one-followings one by one-
1.1. Are there duplicate rows? Find the answer NoAre there duplicate rows? Find the answer No
2.2. Is there primary key? Find the answer yes (thenIs there primary key? Find the answer yes (then
you finished making it in 1 NF)you finished making it in 1 NF)
3.3. Are all the non-key columns functionallyAre all the non-key columns functionally
depend on primary key? Find the answer yesdepend on primary key? Find the answer yes
(then you finished making it 2 NF)(then you finished making it 2 NF)
100Rushdi Shams, Dept of CSE, KUET
The Flow Chart (continued)The Flow Chart (continued)
4.4. Are all the columns that are non key depending fullyAre all the columns that are non key depending fully
functionally upon the primary key? Find the answerfunctionally upon the primary key? Find the answer
yes (then you made it into 3 NF)yes (then you made it into 3 NF)
5.5. Are all the determinants candidate key of the table?Are all the determinants candidate key of the table?
Find the answer yes (then you made it into BCNF)Find the answer yes (then you made it into BCNF)
6.6. Are there multivalued dependency? Find the answerAre there multivalued dependency? Find the answer
no (then you made it into 4 NF)no (then you made it into 4 NF)
7.7. Are there any cyclic dependency? Find the answer noAre there any cyclic dependency? Find the answer no
(then you made it into 5 NF)(then you made it into 5 NF)
8.8. Are there any violation to domain constraints? FindAre there any violation to domain constraints? Find
the answer no (then you made it into DKNF)the answer no (then you made it into DKNF)
101Rushdi Shams, Dept of CSE, KUET
ReferencesReferences
 Designing Effective Database Systems byDesigning Effective Database Systems by
Rebecca M. Riordan, Addison WesleyRebecca M. Riordan, Addison Wesley
Professional, 2005Professional, 2005
 Database Systems by Paul Beynon-Devies,Database Systems by Paul Beynon-Devies,
Palgrave Macmillan, 2004Palgrave Macmillan, 2004
 www.wikipedia.orgwww.wikipedia.org
 Beginning Database Design by GavinBeginning Database Design by Gavin
Powell, Wrox Publications, 2005Powell, Wrox Publications, 2005
102Rushdi Shams, Dept of CSE, KUET
References (continued)References (continued)
 www.techtarget.comwww.techtarget.com
 http://http://databases.about.comdatabases.about.com
 Databases –Normalization by GordonDatabases –Normalization by Gordon
Royle, Department of Computer Science &Royle, Department of Computer Science &
Software Engineering University ofSoftware Engineering University of
Western AustraliaWestern Australia
 Database Management Systems by Prof.Database Management Systems by Prof.
Holowczak, Zicklin School of Business,Holowczak, Zicklin School of Business,
Baruch College, City University of NewBaruch College, City University of New
YorkYork

More Related Content

Similar to Normal forms

My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebraRushdi Shams
 
Multiple intelligences approach to Number Systems
Multiple intelligences approach to  Number SystemsMultiple intelligences approach to  Number Systems
Multiple intelligences approach to Number Systems
Katrin Becker
 
Infrastructures et recommandations pour les Humanités Numériques - Big Data e...
Infrastructures et recommandations pour les Humanités Numériques - Big Data e...Infrastructures et recommandations pour les Humanités Numériques - Big Data e...
Infrastructures et recommandations pour les Humanités Numériques - Big Data e...
Patrice Bellot - Aix-Marseille Université / CNRS (LIS, INS2I)
 
Score Week 5 Correlation and RegressionCorrelation and Regres.docx
Score Week 5 Correlation and RegressionCorrelation and Regres.docxScore Week 5 Correlation and RegressionCorrelation and Regres.docx
Score Week 5 Correlation and RegressionCorrelation and Regres.docx
kenjordan97598
 
BUS308 – Week 1 Lecture 2 Describing Data Expected Out.docx
BUS308 – Week 1 Lecture 2 Describing Data Expected Out.docxBUS308 – Week 1 Lecture 2 Describing Data Expected Out.docx
BUS308 – Week 1 Lecture 2 Describing Data Expected Out.docx
curwenmichaela
 
Fuzzy Querying Based on Relational Database
Fuzzy Querying Based on Relational DatabaseFuzzy Querying Based on Relational Database
Fuzzy Querying Based on Relational Database
IOSR Journals
 
Using Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigDataUsing Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigData
AnalyticsWeek
 
M08 BiasVarianceTradeoff
M08 BiasVarianceTradeoffM08 BiasVarianceTradeoff
M08 BiasVarianceTradeoff
Raman Kannan
 
stacks1
stacks1stacks1
An introduction to ROC analysis
An introduction to ROC analysisAn introduction to ROC analysis
An introduction to ROC analysis
Dr. Volkan OBAN
 
Fuzzy Systems by using fuzzy set (Soft Computing)
Fuzzy Systems by using fuzzy set (Soft Computing)Fuzzy Systems by using fuzzy set (Soft Computing)
Fuzzy Systems by using fuzzy set (Soft Computing)
Amit Kumar Rathi
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
Shani729
 
introduction to Genifer -- Deduction
introduction to Genifer -- Deductionintroduction to Genifer -- Deduction
introduction to Genifer -- DeductionYan Yin
 
Chapter 5 (final)
Chapter 5 (final)Chapter 5 (final)
Chapter 5 (final)
Nateshwar Kamlesh
 
DoW #6 TVs and Life ExpectanciesFor this weeks DoW, you wi.docx
DoW #6 TVs and Life ExpectanciesFor this weeks DoW, you wi.docxDoW #6 TVs and Life ExpectanciesFor this weeks DoW, you wi.docx
DoW #6 TVs and Life ExpectanciesFor this weeks DoW, you wi.docx
kanepbyrne80830
 
Basic statistics by_david_solomon_hadi_-_split_and_reviewed
Basic statistics by_david_solomon_hadi_-_split_and_reviewedBasic statistics by_david_solomon_hadi_-_split_and_reviewed
Basic statistics by_david_solomon_hadi_-_split_and_reviewed
bob panic
 
Dymystify Statistics Day 1.pdf
Dymystify Statistics Day 1.pdfDymystify Statistics Day 1.pdf
Dymystify Statistics Day 1.pdf
KristineIbaez2
 
Fb35884889
Fb35884889Fb35884889
Fb35884889
IJERA Editor
 

Similar to Normal forms (20)

My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebra
 
Unit05 dbms
Unit05 dbmsUnit05 dbms
Unit05 dbms
 
Multiple intelligences approach to Number Systems
Multiple intelligences approach to  Number SystemsMultiple intelligences approach to  Number Systems
Multiple intelligences approach to Number Systems
 
Infrastructures et recommandations pour les Humanités Numériques - Big Data e...
Infrastructures et recommandations pour les Humanités Numériques - Big Data e...Infrastructures et recommandations pour les Humanités Numériques - Big Data e...
Infrastructures et recommandations pour les Humanités Numériques - Big Data e...
 
Score Week 5 Correlation and RegressionCorrelation and Regres.docx
Score Week 5 Correlation and RegressionCorrelation and Regres.docxScore Week 5 Correlation and RegressionCorrelation and Regres.docx
Score Week 5 Correlation and RegressionCorrelation and Regres.docx
 
BUS308 – Week 1 Lecture 2 Describing Data Expected Out.docx
BUS308 – Week 1 Lecture 2 Describing Data Expected Out.docxBUS308 – Week 1 Lecture 2 Describing Data Expected Out.docx
BUS308 – Week 1 Lecture 2 Describing Data Expected Out.docx
 
Fuzzy Querying Based on Relational Database
Fuzzy Querying Based on Relational DatabaseFuzzy Querying Based on Relational Database
Fuzzy Querying Based on Relational Database
 
Using Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigDataUsing Topological Data Analysis on your BigData
Using Topological Data Analysis on your BigData
 
M08 BiasVarianceTradeoff
M08 BiasVarianceTradeoffM08 BiasVarianceTradeoff
M08 BiasVarianceTradeoff
 
stacks1
stacks1stacks1
stacks1
 
An introduction to ROC analysis
An introduction to ROC analysisAn introduction to ROC analysis
An introduction to ROC analysis
 
Fuzzy Systems by using fuzzy set (Soft Computing)
Fuzzy Systems by using fuzzy set (Soft Computing)Fuzzy Systems by using fuzzy set (Soft Computing)
Fuzzy Systems by using fuzzy set (Soft Computing)
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
 
Bioinformatics t4-alignments v2014
Bioinformatics t4-alignments v2014Bioinformatics t4-alignments v2014
Bioinformatics t4-alignments v2014
 
introduction to Genifer -- Deduction
introduction to Genifer -- Deductionintroduction to Genifer -- Deduction
introduction to Genifer -- Deduction
 
Chapter 5 (final)
Chapter 5 (final)Chapter 5 (final)
Chapter 5 (final)
 
DoW #6 TVs and Life ExpectanciesFor this weeks DoW, you wi.docx
DoW #6 TVs and Life ExpectanciesFor this weeks DoW, you wi.docxDoW #6 TVs and Life ExpectanciesFor this weeks DoW, you wi.docx
DoW #6 TVs and Life ExpectanciesFor this weeks DoW, you wi.docx
 
Basic statistics by_david_solomon_hadi_-_split_and_reviewed
Basic statistics by_david_solomon_hadi_-_split_and_reviewedBasic statistics by_david_solomon_hadi_-_split_and_reviewed
Basic statistics by_david_solomon_hadi_-_split_and_reviewed
 
Dymystify Statistics Day 1.pdf
Dymystify Statistics Day 1.pdfDymystify Statistics Day 1.pdf
Dymystify Statistics Day 1.pdf
 
Fb35884889
Fb35884889Fb35884889
Fb35884889
 

More from Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
Rushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
Rushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
Rushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
Rushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Recently uploaded

When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 

Recently uploaded (20)

When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 

Normal forms

  • 1. Rushdi Shams, Dept of CSE, KUET 1 Database SystemsDatabase Systems Normal FormsNormal Forms Version 1.0Version 1.0
  • 2. 2Rushdi Shams, Dept of CSE, KUET NormalizationNormalization  ItIt avoids duplication of dataavoids duplication of data. Hence it is a. Hence it is a tool totool to avoid redundancy of dataavoid redundancy of data..  Theorists gave loads of “do this”, “do that” thing whenTheorists gave loads of “do this”, “do that” thing when relational model was first invoked. One of those wererelational model was first invoked. One of those were normal forms. Applying those theories on databases arenormal forms. Applying those theories on databases are called normalizatoin.called normalizatoin.  But the fact is,But the fact is, in commercial environment, loads ofin commercial environment, loads of works are done by not maintaining theworks are done by not maintaining the normalization theories 100%!normalization theories 100%!
  • 3. 3Rushdi Shams, Dept of CSE, KUET Why Normalization?Why Normalization?
  • 4. 4Rushdi Shams, Dept of CSE, KUET Why Normalization? (continued)Why Normalization? (continued)  What if we want to delete the student no 34668?What if we want to delete the student no 34668? Alas! We will lose information about DEDUCTIVEAlas! We will lose information about DEDUCTIVE DATABASE, its lecturer name and many more!DATABASE, its lecturer name and many more!  What if we want to update the lecturer to NICKWhat if we want to update the lecturer to NICK WHITTAKER? We will have to put staff name as wellWHITTAKER? We will have to put staff name as well as staff no for that!as staff no for that!  What if we want to insert a new student with numberWhat if we want to insert a new student with number 38989? We cannot insert any student who does not38989? We cannot insert any student who does not have any assessment criteria!have any assessment criteria!
  • 5. 5Rushdi Shams, Dept of CSE, KUET AnomaliesAnomalies  An anomaly is a bad thing. Because it tends theAn anomaly is a bad thing. Because it tends the data in a database LOGICALLY getdata in a database LOGICALLY get corrupted!corrupted!  There are mainly 3 types of anomaliesThere are mainly 3 types of anomalies 1.1. Insert anomalyInsert anomaly 2.2. Delete anomalyDelete anomaly 3.3. Update anomalyUpdate anomaly The reason why I switched to discuss aboutThe reason why I switched to discuss about anomaly- you will understand later!anomaly- you will understand later!
  • 6. 6Rushdi Shams, Dept of CSE, KUET Insert AnomalyInsert Anomaly  It is caused when an insertion takes place in aIt is caused when an insertion takes place in a child table, where there is no record in thechild table, where there is no record in the parent table!parent table!
  • 7. 7Rushdi Shams, Dept of CSE, KUET Insert Anomaly (continued)Insert Anomaly (continued)  What if you try to insertWhat if you try to insert a book of J K Rawlingsa book of J K Rawlings into the table left withoutinto the table left without putting her name into theputting her name into the table below?table below?
  • 8. 8Rushdi Shams, Dept of CSE, KUET Delete AnomalyDelete Anomaly  Caused when a data in the parent table is deletedCaused when a data in the parent table is deleted before deleting all the related data from its childbefore deleting all the related data from its child (ren) table(s).(ren) table(s).  Well, if you prefer a cascaded deletion, no oneWell, if you prefer a cascaded deletion, no one would mind!would mind!
  • 9. 9Rushdi Shams, Dept of CSE, KUET Delete Anomaly (continued)Delete Anomaly (continued)  Before deleting the dataBefore deleting the data from the table below, iffrom the table below, if you delete data fromyou delete data from table in right, what dotable in right, what do you think it is gonnayou think it is gonna happen?happen?
  • 10. 10Rushdi Shams, Dept of CSE, KUET Update AnomalyUpdate Anomaly  It is kind of like delete anomaly. Both the parentIt is kind of like delete anomaly. Both the parent table and child(ren) table(s) should get updatedtable and child(ren) table(s) should get updated concurrently!concurrently!
  • 11. 11Rushdi Shams, Dept of CSE, KUET More JargonsMore Jargons  Well, before starting with normalizations, youWell, before starting with normalizations, you must need to know some jargons. You alreadymust need to know some jargons. You already are aware of anomalies. Let’s get into someare aware of anomalies. Let’s get into some more!more!
  • 12. 12Rushdi Shams, Dept of CSE, KUET Functional DependencyFunctional Dependency  Y is functionally dependent on X if the values ofY is functionally dependent on X if the values of Y are determined by the values of X.Y are determined by the values of X.  Y=X+1. In this case, Y is functionallyY=X+1. In this case, Y is functionally dependent on Xdependent on X  y=f(x). In this generic case, y is functionallyy=f(x). In this generic case, y is functionally dependent on x as well.dependent on x as well.
  • 13. 13Rushdi Shams, Dept of CSE, KUET Functional Dependency (continued)Functional Dependency (continued)  In this case, CURRENCY is functionallyIn this case, CURRENCY is functionally dependent on FXCODEdependent on FXCODE
  • 14. 14Rushdi Shams, Dept of CSE, KUET DeterminantDeterminant  If X determines the values of Y, then X will beIf X determines the values of Y, then X will be called the determinant of Ycalled the determinant of Y  Y=X+1. In this case, X is determinant of Y.Y=X+1. In this case, X is determinant of Y.  y=f(x). In this case, x is determinant of y as well.y=f(x). In this case, x is determinant of y as well.
  • 15. 15Rushdi Shams, Dept of CSE, KUET Determinant (continued)Determinant (continued)  In this case, FXCODE is determinant ofIn this case, FXCODE is determinant of CURRENCY.CURRENCY.
  • 16. 16Rushdi Shams, Dept of CSE, KUET Transitive DependencyTransitive Dependency  If the value of Z is determined by Y and theIf the value of Z is determined by Y and the value of Y is determined by X, then there is avalue of Y is determined by X, then there is a transitive dependency between X and Z.transitive dependency between X and Z.  This dependency thus states the indirectThis dependency thus states the indirect dependency.dependency. BackBack
  • 17. 17Rushdi Shams, Dept of CSE, KUET Transitive Dependency (continued)Transitive Dependency (continued)  In this case, RATE is dependent onIn this case, RATE is dependent on CURRENCY. CURRENCY is dependent onCURRENCY. CURRENCY is dependent on COUNTRY. So, RATE is transitively dependentCOUNTRY. So, RATE is transitively dependent on COUNTRY.on COUNTRY.
  • 18. 18Rushdi Shams, Dept of CSE, KUET Candidate keyCandidate key  It is theIt is the minimal setminimal set of super key.of super key.  Say, from this example, you only can have super keysSay, from this example, you only can have super keys as followings (though you may have otheras followings (though you may have other combinations, but just shorten that this time)-combinations, but just shorten that this time)- {roll, name}, {roll, name, dept}, {roll, name, year,{roll, name}, {roll, name, dept}, {roll, name, year, semester}semester} In this case, the candidate key is {roll, name}!In this case, the candidate key is {roll, name}! RollRoll NameName DeptDept YearYear SemestSemest erer
  • 19. 19Rushdi Shams, Dept of CSE, KUET Full Functional DependencyFull Functional Dependency  If X determines Y but X with combination of ZIf X determines Y but X with combination of Z does not determine Y- then, there is a fulldoes not determine Y- then, there is a full functional dependency between X and Y.functional dependency between X and Y.  So, X cannot be a composite key.So, X cannot be a composite key. Nb. If you make a key with 2 or more columns,Nb. If you make a key with 2 or more columns, then that is called a composite key.then that is called a composite key.
  • 20. 20Rushdi Shams, Dept of CSE, KUET Full Functional DependencyFull Functional Dependency (continued)(continued)  In this case,In this case, POPULATION dependsPOPULATION depends on COUNTRY not onon COUNTRY not on the combination ofthe combination of RATE andRATE and COUNTRY. So,COUNTRY. So, POPULATION is fullyPOPULATION is fully functional dependent onfunctional dependent on COUNTRY and also youCOUNTRY and also you can say that,can say that, POPULATION is notPOPULATION is not fully functionalfully functional dependent on RATE anddependent on RATE and COUNTRY!COUNTRY!
  • 21. 21Rushdi Shams, Dept of CSE, KUET 11stst Normal Form: 1NFNormal Form: 1NF  Academic Definitions:Academic Definitions: 1. Eliminate repeating groups such that all records in all tables can be identified uniquely by a primary key in each table. In other words, all fields other than the primary key must depend on the primary key. 2. A relation is in first normal form if and only if every non-key attribute is functionally dependent upon the primary key
  • 22. 22Rushdi Shams, Dept of CSE, KUET 1 NF (continued)1 NF (continued) 3. A relation is in first normal form if the domains on which its attributes are defined are scalar BackBack
  • 23. 23Rushdi Shams, Dept of CSE, KUET 1 NF (continued)1 NF (continued)  Easy Definition:Easy Definition: 1 NF is a process of removing repeating groups1 NF is a process of removing repeating groups from a table by creating a new tablefrom a table by creating a new table They are linked by a one to many relationshipThey are linked by a one to many relationship Create primary keys on both tablesCreate primary keys on both tables The child table will have a composite primaryThe child table will have a composite primary key (one of its own, other is its foreign key fromkey (one of its own, other is its foreign key from its parent table)its parent table)
  • 24. 24Rushdi Shams, Dept of CSE, KUET What does 1 NF do?What does 1 NF do?  Academic Way:Academic Way:  Eliminates repeating groupsEliminates repeating groups  Defines primary keysDefines primary keys  No duplicate entry allowedNo duplicate entry allowed  All fields other than primary key depend on primaryAll fields other than primary key depend on primary keykey  All columns must contain a single value (seeAll columns must contain a single value (see Definition 3Definition 3))  All values in a column must have the same data typeAll values in a column must have the same data type  Create a table to move repeating data from the currentCreate a table to move repeating data from the current tabletable
  • 25. 25Rushdi Shams, Dept of CSE, KUET Not Scalar- Not 1 NFNot Scalar- Not 1 NF
  • 26. 26Rushdi Shams, Dept of CSE, KUET Repeating Groups- Not 1 NFRepeating Groups- Not 1 NF
  • 27. 27Rushdi Shams, Dept of CSE, KUET 0 NF to 1 NF0 NF to 1 NF  Remove repeatingRemove repeating groups. Split table intogroups. Split table into tables with one to manytables with one to many relationship.relationship.
  • 28. 28Rushdi Shams, Dept of CSE, KUET 0 NF to 1 NF (continued)0 NF to 1 NF (continued)  Creating primary key onCreating primary key on parent table andparent table and composite primary keycomposite primary key on child table (where iton child table (where it has a foreign keyhas a foreign key referenced to parentreferenced to parent table)table)
  • 29. 29Rushdi Shams, Dept of CSE, KUET Our 1 NFOur 1 NF
  • 30. 30Rushdi Shams, Dept of CSE, KUET Can you do it?Can you do it?
  • 31. 31Rushdi Shams, Dept of CSE, KUET Yes! You Can!!Yes! You Can!!
  • 32. 32Rushdi Shams, Dept of CSE, KUET Second Normal Form- 2 NFSecond Normal Form- 2 NF  Academic Definition:Academic Definition: 1. A relation is in second normal form if and only if it is in first normal form and every non-key attribute is fully functionally dependent on the primary key 2.2. A relation is in second normal form ifA relation is in second normal form if it is init is in first normal formfirst normal form and, in addition,and, in addition, all itsall its attributes are dependent on the entireattributes are dependent on the entire candidate keycandidate key
  • 33. 33Rushdi Shams, Dept of CSE, KUET What does 2 NF do?What does 2 NF do?  Academic Way:Academic Way:  The table is in 1 NFThe table is in 1 NF  All non-key values must be functionally dependent on the primary key. In other words, non-key fields not dependent on the primary key are not allowed.  Partial dependencies must be removed. A partial dependency is a special type of functional dependency that exists when a field is dependant on a part of a composite primary key.  Create a table with partially dependent part of the primary key and its dependents.
  • 34. 34Rushdi Shams, Dept of CSE, KUET Which is not 2 NF?Which is not 2 NF? Solution!Solution!
  • 35. 35Rushdi Shams, Dept of CSE, KUET 1 NF to 2 NF1 NF to 2 NF
  • 36. 36Rushdi Shams, Dept of CSE, KUET Separating TablesSeparating Tables
  • 37. 37Rushdi Shams, Dept of CSE, KUET Providing Many to One RelationProviding Many to One Relation
  • 38. 38Rushdi Shams, Dept of CSE, KUET Providing One to Many RelationshipProviding One to Many Relationship
  • 39. 39Rushdi Shams, Dept of CSE, KUET Can You Do It?Can You Do It?
  • 40. 40Rushdi Shams, Dept of CSE, KUET Yes! You Can!!Yes! You Can!!
  • 41. 41Rushdi Shams, Dept of CSE, KUET Remember Me? I was not 2 NF!!Remember Me? I was not 2 NF!! See Me!See Me!
  • 42. 42Rushdi Shams, Dept of CSE, KUET 33rdrd Normal Form- 3 NFNormal Form- 3 NF  Academic Way:Academic Way:  The table must be in 2 NFThe table must be in 2 NF  Eliminate transitive dependency (Eliminate transitive dependency ( see Transitive Dependencysee Transitive Dependency))  Create a new table to contain any separatedCreate a new table to contain any separated columnscolumns
  • 43. 43Rushdi Shams, Dept of CSE, KUET 3 NF3 NF  Easy Way:Easy Way:  Meet the requirements by 1 NF and 2 NFMeet the requirements by 1 NF and 2 NF  Remove columns that are not fully dependentRemove columns that are not fully dependent on the primary keyon the primary key
  • 44. 44Rushdi Shams, Dept of CSE, KUET 3 NF (case study)3 NF (case study)  Imagine we have a table that contains theImagine we have a table that contains the following columns-following columns- 1.1. Order numberOrder number 2.2. Customer numberCustomer number 3.3. Unit priceUnit price 4.4. QuantityQuantity 5.5. TotalTotal
  • 45. 45Rushdi Shams, Dept of CSE, KUET 3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in 1 NF1 NF 1.1. Order numberOrder number 2.2. Customer numberCustomer number 3.3. Unit priceUnit price 4.4. QuantityQuantity 5.5. TotalTotal  Are there duplicate columns? No!Are there duplicate columns? No!  Do we have a primary key? Yes, the order number!Do we have a primary key? Yes, the order number!  Fine, it is in 1 NF then!!Fine, it is in 1 NF then!!
  • 46. 46Rushdi Shams, Dept of CSE, KUET 3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in 2 NF2 NF 1.1. Order numberOrder number 2.2. Customer numberCustomer number 3.3. Unit priceUnit price 4.4. QuantityQuantity 5.5. TotalTotal  Are there any static of data that apply toAre there any static of data that apply to multiple rows? No!multiple rows? No!  Fine, we are in 2 NF then!!Fine, we are in 2 NF then!!
  • 47. 47Rushdi Shams, Dept of CSE, KUET 3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in 3 NF3 NF 1.1. Order numberOrder number 2.2. Customer numberCustomer number 3.3. Unit priceUnit price 4.4. QuantityQuantity 5.5. TotalTotal  Are all of the columns fully depend on theAre all of the columns fully depend on the primary key (order number)?primary key (order number)?
  • 48. 48Rushdi Shams, Dept of CSE, KUET 3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in 3 NF (continued)3 NF (continued)  The customer number varies with the order numberThe customer number varies with the order number and it doesn't appear to depend upon any of the otherand it doesn't appear to depend upon any of the other fieldsfields  What about the unit price? This field could beWhat about the unit price? This field could be dependent upon the customer number in a situationdependent upon the customer number in a situation where we charged each customer a set price. However,where we charged each customer a set price. However, looking at the data above, it appears we sometimeslooking at the data above, it appears we sometimes charge the same customer different prices. Therefore,charge the same customer different prices. Therefore, the unit price is fully dependent upon the order numberthe unit price is fully dependent upon the order number
  • 49. 49Rushdi Shams, Dept of CSE, KUET 3 NF (case study): Checking if it is in3 NF (case study): Checking if it is in 3 NF (continued)3 NF (continued)  The quantity of items also varies from order toThe quantity of items also varies from order to order, so we're OK there.order, so we're OK there.  What about the total? It looks like we might beWhat about the total? It looks like we might be in trouble here. The total can be derived byin trouble here. The total can be derived by multiplying the unit price by the quantity,multiplying the unit price by the quantity, therefore it's not fully dependent upon thetherefore it's not fully dependent upon the primary key. We must remove it from the tableprimary key. We must remove it from the table to comply with the third normal form.to comply with the third normal form.
  • 50. 50Rushdi Shams, Dept of CSE, KUET 3 NF (case study): Making it a 3 NF3 NF (case study): Making it a 3 NF 1.1. Order numberOrder number 2.2. Customer numberCustomer number 3.3. Unit priceUnit price 4.4. QuantityQuantity  Now, the table is in 3 NF. What about total?Now, the table is in 3 NF. What about total? Well, there is no need to put it on a separateWell, there is no need to put it on a separate table! You can make a select command to grabtable! You can make a select command to grab the total by multiplying unit price withthe total by multiplying unit price with quantity- can’t you?quantity- can’t you?
  • 51. 51Rushdi Shams, Dept of CSE, KUET 3 NF3 NF  Did you see theDid you see the irrelevant columns in theirrelevant columns in the 2 tables?2 tables?  You need to separateYou need to separate them!them!
  • 52. 52Rushdi Shams, Dept of CSE, KUET 3 NF (continued)3 NF (continued)  Eliminated the irrelevantEliminated the irrelevant columns and makingcolumns and making them a separate table.them a separate table.
  • 53. 53Rushdi Shams, Dept of CSE, KUET 3 NF (continued)3 NF (continued)  Can you see theCan you see the irrelevant column here?irrelevant column here?  You need to separateYou need to separate them to make it a 3 NF!them to make it a 3 NF!
  • 54. 54Rushdi Shams, Dept of CSE, KUET 3 NF (continued)3 NF (continued)
  • 55. 55Rushdi Shams, Dept of CSE, KUET 3 NF (continued)3 NF (continued)  Did you see the columnDid you see the column that does not depend onthat does not depend on the primary key?the primary key?  You need to separateYou need to separate that column from thethat column from the table to make it 3 NFtable to make it 3 NF
  • 56. 56Rushdi Shams, Dept of CSE, KUET 3 NF (continued)3 NF (continued)
  • 57. 57Rushdi Shams, Dept of CSE, KUET Can you do it?Can you do it?
  • 58. 58Rushdi Shams, Dept of CSE, KUET Yes! You Can!!Yes! You Can!!
  • 59. 59Rushdi Shams, Dept of CSE, KUET Be warned!Be warned!  3 NF is said to be the most crucial and most3 NF is said to be the most crucial and most ambiguous, most complex part of normalization!ambiguous, most complex part of normalization!
  • 60. 60Rushdi Shams, Dept of CSE, KUET Bad thing of too much normalizationBad thing of too much normalization  Did you take a look at the number of tableDid you take a look at the number of table increased from 0 NF to 3 NF? If it is a bigincreased from 0 NF to 3 NF? If it is a big enterprise database, then can you imagine howenterprise database, then can you imagine how far this can go?far this can go?  Too many tables lead us to too many joinsToo many tables lead us to too many joins  Joins are one of the complex codings and timeJoins are one of the complex codings and time consuming subtle entities in database systemsconsuming subtle entities in database systems  So, try to normalize, but don’t normalize in aSo, try to normalize, but don’t normalize in a way that you have 1000 tables!way that you have 1000 tables!
  • 61. 61Rushdi Shams, Dept of CSE, KUET Beyond 3 NFBeyond 3 NF  Most software development firms dealing withMost software development firms dealing with database systems do not go beyond 3 NF anddatabase systems do not go beyond 3 NF and many of them even try not to reach 3 NF!!many of them even try not to reach 3 NF!!
  • 62. 62Rushdi Shams, Dept of CSE, KUET Boyce Codd Normal Form (BCNF)Boyce Codd Normal Form (BCNF)  It is a variation of 3 NFIt is a variation of 3 NF  In a 3NF table, all attributes are dependent on a key, aIn a 3NF table, all attributes are dependent on a key, a whole key and nothing but a keywhole key and nothing but a key  A table is said to be in BCNF if and only if it is in 3NFA table is said to be in BCNF if and only if it is in 3NF and every non-trivial, left-irreducible functionaland every non-trivial, left-irreducible functional dependency has a candidate key as its determinantdependency has a candidate key as its determinant  In more informal terms, a table is in BCNF if it is inIn more informal terms, a table is in BCNF if it is in 3NF and the only determinants are the candidate keys3NF and the only determinants are the candidate keys
  • 63. 63Rushdi Shams, Dept of CSE, KUET BCNF (continued)BCNF (continued)
  • 64. 64Rushdi Shams, Dept of CSE, KUET BCNF (continued)BCNF (continued)  Primary key is product category and productPrimary key is product category and product subcategorysubcategory  The table is in 3NF, for each of its non-key attributes isThe table is in 3NF, for each of its non-key attributes is non-transitively dependent on the full key (Productnon-transitively dependent on the full key (Product Category, Product Subcategory).Category, Product Subcategory).
  • 65. 65Rushdi Shams, Dept of CSE, KUET BCNF (continued)BCNF (continued)  Yet the table has redundant data. Look at column 1,Yet the table has redundant data. Look at column 1, column 3 and column 4 for the last 4 rows!column 3 and column 4 for the last 4 rows!
  • 66. 66Rushdi Shams, Dept of CSE, KUET BCNF (continued)BCNF (continued)  Indeed, Range Code is dictated by the combination of ProductIndeed, Range Code is dictated by the combination of Product Category and Stock CategoryCategory and Stock Category  Is stock category a candidate key? NO! Then it is not in BCNF!!Is stock category a candidate key? NO! Then it is not in BCNF!!
  • 67. 67Rushdi Shams, Dept of CSE, KUET BCNF (continued)BCNF (continued)  The point about BCNF is that a candidate key is, by definition, a unique key, and thus a potential primary key.  If a table contains more than one candidate key (primary key), it has a problem according to BCNF. I disagree!  BCNF divides a table up into multiple tables to ensure that no single table has more than one potential primary key  BCNF prohibits a table from having two possible primary keys.
  • 68. 68Rushdi Shams, Dept of CSE, KUET Anomaly problemAnomaly problem  In this table, say, studentNo and Area is primary keyIn this table, say, studentNo and Area is primary key
  • 69. 69Rushdi Shams, Dept of CSE, KUET Anomaly problemAnomaly problem  What if 123456 wants to change her subject toWhat if 123456 wants to change her subject to information systems? We will lose the data-information systems? We will lose the data- who is taking the course computer science?who is taking the course computer science?  This is update anomalyThis is update anomaly
  • 70. 70Rushdi Shams, Dept of CSE, KUET Anomaly problemAnomaly problem  What if staff 250 also will take computer science? IfWhat if staff 250 also will take computer science? If there is no student enrolled in that subject, then wethere is no student enrolled in that subject, then we cannot insert that information in this table!!cannot insert that information in this table!!  This is insert anomalyThis is insert anomaly
  • 71. 71Rushdi Shams, Dept of CSE, KUET Anomaly problemAnomaly problem  What if 123456 wants to withdraw from the courseWhat if 123456 wants to withdraw from the course Software Engineering? We will lose the data-Software Engineering? We will lose the data- Who will take the course Software Engineering!!Who will take the course Software Engineering!!  This is delete anomalyThis is delete anomaly
  • 72. 72Rushdi Shams, Dept of CSE, KUET Why anomaly?Why anomaly?  The anomalies occurred because, there are twoThe anomalies occurred because, there are two overlapping candidate keys- student number andoverlapping candidate keys- student number and area!area!
  • 73. 73Rushdi Shams, Dept of CSE, KUET Normalizing to BCNFNormalizing to BCNF  Suppose a relation R is not inSuppose a relation R is not in BCNFBCNF. Then there must be some. Then there must be some functional dependency X → A where X is not a superkey.functional dependency X → A where X is not a superkey.  In this case, the relation can be decomposed into the twoIn this case, the relation can be decomposed into the two relationsrelations 1.1. R1= R − AR1= R − A 2.2. R2= XAR2= XA  where R − A simply means dropping the attribute A from thewhere R − A simply means dropping the attribute A from the schema and XA is the relation whose attributes are those in Xschema and XA is the relation whose attributes are those in X together with Atogether with A  Then examine the new tables if you can apply 1 and 2 on themThen examine the new tables if you can apply 1 and 2 on them again!again!  When you cannot apply 1 and 2 on them, then it’s in BCNF!!When you cannot apply 1 and 2 on them, then it’s in BCNF!!
  • 74. 74Rushdi Shams, Dept of CSE, KUET BCNF ExampleBCNF Example  Product category+stock category determines range code.Product category+stock category determines range code.  So, make two tables.So, make two tables. 1.1. Product category, product subcategory, stock category, rangeProduct category, product subcategory, stock category, range subcodesubcode 2.2. Product category, stock category, range codeProduct category, stock category, range code
  • 75. 75Rushdi Shams, Dept of CSE, KUET BCNF example (continued)BCNF example (continued)
  • 76. 76Rushdi Shams, Dept of CSE, KUET BCNF example (continued)BCNF example (continued)  Now, observe this new table. In it, the range subcodeNow, observe this new table. In it, the range subcode depends on stock category and product subcategory.depends on stock category and product subcategory. So, make two tables.So, make two tables. 1.1. Product category, product subcategory, stock categoryProduct category, product subcategory, stock category 2.2. Product subcategory, stock category, range subcodeProduct subcategory, stock category, range subcode
  • 77. 77Rushdi Shams, Dept of CSE, KUET BCNF example (continued)BCNF example (continued)
  • 78. 78Rushdi Shams, Dept of CSE, KUET Our tables in BCNFOur tables in BCNF
  • 79. 79Rushdi Shams, Dept of CSE, KUET Fourth Normal Form (4 NF)Fourth Normal Form (4 NF)  A table must be in 3 NF or BCNF with 3 NFA table must be in 3 NF or BCNF with 3 NF  Multi-valued dependencies must be transformed into functional dependencies. This implies that one value and not multiple values are dependent on a primary key.  Eliminate multiple sets of multiple valued or multi-valued dependencies, sometimes described as non-trivial multi-valued dependencies.  NF and has no multiple sets of multi-valued dependencies. In other words, 4NF states that no entity can have more than a single one-to-many relationship within an entity if the one-to- many attributes are independent of each other.
  • 80. 80Rushdi Shams, Dept of CSE, KUET 4 NF Example4 NF Example  In this table, there are 3In this table, there are 3 columns. Employee, skillcolumns. Employee, skill and skilllanguageand skilllanguage  Employee is the primaryEmployee is the primary keykey  The table is in BCNFThe table is in BCNF with 3NFwith 3NF
  • 81. 81Rushdi Shams, Dept of CSE, KUET 4 NF Example4 NF Example  The record for employeeThe record for employee number 0122443 can benumber 0122443 can be written also in the form-written also in the form- 0122443: Typing,0122443: Typing, Dictation: English,Dictation: English, French in the formFrench in the form employee: skill:employee: skill: skilllanguageskilllanguage
  • 82. 82Rushdi Shams, Dept of CSE, KUET 4 NF Example4 NF Example  So, the multivaluedSo, the multivalued dependency is on skilldependency is on skill column and skilllanguagecolumn and skilllanguage column!column!  To make it in 4 NF, youTo make it in 4 NF, you will have to simply splitwill have to simply split them into separate table,them into separate table, nothing else!!nothing else!!
  • 83. 83Rushdi Shams, Dept of CSE, KUET 4 NF Example4 NF Example
  • 84. 84Rushdi Shams, Dept of CSE, KUET Solving one, creates anotherSolving one, creates another problem!problem!  Can you say, what is the problem still with theCan you say, what is the problem still with the tables?tables?  There are still 2 entries for the same employee!!There are still 2 entries for the same employee!!
  • 85. 85Rushdi Shams, Dept of CSE, KUET Fifth Normal Form (5 NF)Fifth Normal Form (5 NF)  Personally, I really hate this form!!Personally, I really hate this form!!  The table must have to be in 4 NF (same oldThe table must have to be in 4 NF (same old dialogue!)dialogue!)  The table should not contain any cyclicThe table should not contain any cyclic dependency!dependency!  Cyclic dependency is like say your table has 3Cyclic dependency is like say your table has 3 columns. Column 1 depends on 2, 2 on 3 and 3columns. Column 1 depends on 2, 2 on 3 and 3 on 1!!on 1!!  Also known as PJNF (Projection Normal Form)Also known as PJNF (Projection Normal Form)
  • 86. 86Rushdi Shams, Dept of CSE, KUET 5 NF (continued)5 NF (continued)  Try begin with creating a table EmployeesTry begin with creating a table Employees  All the 3 columns are primary key (kind of weird, isn’tAll the 3 columns are primary key (kind of weird, isn’t it?? We can call it composite primary key)it?? We can call it composite primary key)
  • 87. 87Rushdi Shams, Dept of CSE, KUET 5 NF (continued)5 NF (continued)  Let’s insert some data in Employees table then.Let’s insert some data in Employees table then.
  • 88. 88Rushdi Shams, Dept of CSE, KUET 5 NF (continued)5 NF (continued)  Employees table now look like this!Employees table now look like this!  There is no multivalued dependency, so, the table is inThere is no multivalued dependency, so, the table is in 4 NF (of course also in 1-2-3-BC NF!!)4 NF (of course also in 1-2-3-BC NF!!)
  • 89. 89Rushdi Shams, Dept of CSE, KUET 5 NF (continued)5 NF (continued)  Now, let’s play with the basic table Employees. We willNow, let’s play with the basic table Employees. We will split the table into three tables. WHY? I will say yousplit the table into three tables. WHY? I will say you later.later.  We are making three tables- project_employee,We are making three tables- project_employee, project_manager, manager_employeeproject_manager, manager_employee
  • 90. 90Rushdi Shams, Dept of CSE, KUET Detail of project_employeeDetail of project_employee
  • 91. 91Rushdi Shams, Dept of CSE, KUET Detail of project_managerDetail of project_manager
  • 92. 92Rushdi Shams, Dept of CSE, KUET Detail of manager_employeeDetail of manager_employee
  • 93. 93Rushdi Shams, Dept of CSE, KUET The Fun!The Fun!  Now, we will query the initial table Employees! It will show usNow, we will query the initial table Employees! It will show us the whole tablethe whole table
  • 94. 94Rushdi Shams, Dept of CSE, KUET The Fun Continues!The Fun Continues!  Now, we will join the three new tables and will get theNow, we will join the three new tables and will get the same answer!!same answer!!
  • 95. 95Rushdi Shams, Dept of CSE, KUET So, what is the fun for?So, what is the fun for?  The fun is, if you have a table in 4 NF but withThe fun is, if you have a table in 4 NF but with cyclic dependency, if you can split it into xcyclic dependency, if you can split it into x number of tables and then while joining those xnumber of tables and then while joining those x number of tables, it will give you back the initialnumber of tables, it will give you back the initial table, you then made it 5 NF while splitting!table, you then made it 5 NF while splitting!  Phew!!Phew!!
  • 96. 96Rushdi Shams, Dept of CSE, KUET Domain Key Normal Form (DKNF)Domain Key Normal Form (DKNF)  Please god, help us! There are loads of normalPlease god, help us! There are loads of normal forms! I cannot go beyond that! Well, folks, thisforms! I cannot go beyond that! Well, folks, this one is the last- I promise!!one is the last- I promise!!  Domain/key normal form (DKNF) is a normalDomain/key normal form (DKNF) is a normal used in database normalization which requiresused in database normalization which requires that the database contains no constraints otherthat the database contains no constraints other than domain constraints and key constraints.than domain constraints and key constraints.
  • 97. 97Rushdi Shams, Dept of CSE, KUET DKNF (continued)DKNF (continued)  This table violates the rules for being DKNFThis table violates the rules for being DKNF  If Wealthy person type is Eccentric Millionaire/ evil millionaire,If Wealthy person type is Eccentric Millionaire/ evil millionaire, then the Net Worth in Dollars must be 1,000,000 to 999,999,999then the Net Worth in Dollars must be 1,000,000 to 999,999,999 inclusive and if that is Evil Billionaire/ Eccentric Billionaire, theninclusive and if that is Evil Billionaire/ Eccentric Billionaire, then it should be 1,000,000,000 or higher.it should be 1,000,000,000 or higher.
  • 98. 98Rushdi Shams, Dept of CSE, KUET So, what to do?So, what to do?  Nothing serious, the violation on domain can be solvedNothing serious, the violation on domain can be solved easily by changing the domain of Wealthy Person Typeeasily by changing the domain of Wealthy Person Type to Eccentric and Evil- forget about Millionaire andto Eccentric and Evil- forget about Millionaire and Billionaire!!Billionaire!!  It is then in DKNF!!It is then in DKNF!!
  • 99. 99Rushdi Shams, Dept of CSE, KUET The Flow chartThe Flow chart  Say, you are given a table in 0 NF. Do theSay, you are given a table in 0 NF. Do the followings one by one-followings one by one- 1.1. Are there duplicate rows? Find the answer NoAre there duplicate rows? Find the answer No 2.2. Is there primary key? Find the answer yes (thenIs there primary key? Find the answer yes (then you finished making it in 1 NF)you finished making it in 1 NF) 3.3. Are all the non-key columns functionallyAre all the non-key columns functionally depend on primary key? Find the answer yesdepend on primary key? Find the answer yes (then you finished making it 2 NF)(then you finished making it 2 NF)
  • 100. 100Rushdi Shams, Dept of CSE, KUET The Flow Chart (continued)The Flow Chart (continued) 4.4. Are all the columns that are non key depending fullyAre all the columns that are non key depending fully functionally upon the primary key? Find the answerfunctionally upon the primary key? Find the answer yes (then you made it into 3 NF)yes (then you made it into 3 NF) 5.5. Are all the determinants candidate key of the table?Are all the determinants candidate key of the table? Find the answer yes (then you made it into BCNF)Find the answer yes (then you made it into BCNF) 6.6. Are there multivalued dependency? Find the answerAre there multivalued dependency? Find the answer no (then you made it into 4 NF)no (then you made it into 4 NF) 7.7. Are there any cyclic dependency? Find the answer noAre there any cyclic dependency? Find the answer no (then you made it into 5 NF)(then you made it into 5 NF) 8.8. Are there any violation to domain constraints? FindAre there any violation to domain constraints? Find the answer no (then you made it into DKNF)the answer no (then you made it into DKNF)
  • 101. 101Rushdi Shams, Dept of CSE, KUET ReferencesReferences  Designing Effective Database Systems byDesigning Effective Database Systems by Rebecca M. Riordan, Addison WesleyRebecca M. Riordan, Addison Wesley Professional, 2005Professional, 2005  Database Systems by Paul Beynon-Devies,Database Systems by Paul Beynon-Devies, Palgrave Macmillan, 2004Palgrave Macmillan, 2004  www.wikipedia.orgwww.wikipedia.org  Beginning Database Design by GavinBeginning Database Design by Gavin Powell, Wrox Publications, 2005Powell, Wrox Publications, 2005
  • 102. 102Rushdi Shams, Dept of CSE, KUET References (continued)References (continued)  www.techtarget.comwww.techtarget.com  http://http://databases.about.comdatabases.about.com  Databases –Normalization by GordonDatabases –Normalization by Gordon Royle, Department of Computer Science &Royle, Department of Computer Science & Software Engineering University ofSoftware Engineering University of Western AustraliaWestern Australia  Database Management Systems by Prof.Database Management Systems by Prof. Holowczak, Zicklin School of Business,Holowczak, Zicklin School of Business, Baruch College, City University of NewBaruch College, City University of New YorkYork