Relational Database Design Fundamentals
Relational Database Design Fundamentals
Syllabus
Relational Model : Basic concepts, Attributes and Domains, CODD's Rules. Relational
Integrity : Domain, Referential Integrities, Enterprise Constraints. Database Design : Features of
Good Relational Designs, Normalization, Atomic Domains and First Normal Form, Decomposition
using Functional Dependencies, Algorithms for Decomposition, 2NF, 3NF, BCNF.
Contents
Part I : Relational Model
4.1 Basic Concepts
4.2 Attributes and Domains
4.3 CODD's Rules ............................................... Aug.-17
............................................... Oct.-19 .................................. Marks 5
Part II : Relational Integrity
4.4 Keys
4.5 Constraints ............................................... May-18, Dec.-19 ................... Marks 5
4.6 Enterprise Constraints
Part III : Database Design
4.7 Features of Good Relational Designs ...................... Dec.-18,
............................................... Aug.-17 ................................. Marks 5
4.8 Data Redundancy and Update Anomalies
4.9 Normalization ............................................... Dec.-1.................................... Marks 5
4.10 Atomic Domains and First Normal Form
4.11 Decomposition using Functional Dependencies ...... Oct.-19
............................................... May-18 .................................. Marks 5
4.12 Equivalence and Minimal Cover
4.13 Algorithms for Decomposition
4.14 Lossless Join ............................................... May-18 .................................. Marks 6
(4 - 1)
Database Management Systems 4-2 Relational Database Design
101 Mechanical 4
103 Electrical 5
104 Civil 3
Clearly, in above table the columns are CourseID, CourseName and Credits. The
CourseID 101 is associated with the course named Mechanical and associated with the
course of mechanical there are 4 credit points. Thus the relation is represented by the
table in the relation model. Similarly we can establish the relationship among the two
tables by defining the third table. For example – Consider the table Admission as
RollNo CourseID
001 102
002 104
003 101
From this third table we can easily find out that the course to which the RollNo 001 is
admitted is computer Science.
Tuple or record or row : The single entry in the table is called tuple. The tuple
represents a set of related data. In above Student table there are four tuples. One of the
tuple can be represented as
001 AAA 88 1111111111
Attribute or columns : It is a part of table that contains several records. Each record
can be broken down into several small parts of data known as attributes. For example the
above table consists of four attributes such as RollNo,Name,Marks and Phone.
Relation schema : A relation schema describes the structure of the relation, with the
name of the relation (i.e. name of table), its attributes and their names and type.
Relation Instance : It refers to specific instance of relation i.e. containing a specific set
of rows. For example – the following is a relation instance – which contains the records
with marks above 80.
RollNo Name Marks Phone
Degree : It is nothing but total number of columns present in the relational database.
In given Student table –
Roll No Name Marks Phone
001 AAA 88 1111111111
002 BBB 83 2222222222
003 CCC 98 3333333333
The degree is 4.
Cardinality : It is total number of tuples present in the relational database. In above
given table the cardinality is 3
Example 4.2.1 Find out following for given Staff table
i) No of Columns ii) No of tuples
iii) Different attributes iv) Degree v) Cardinality
i) No of Columns = 6
ii) No of Tuples = 3
iii) Different attributes are StaffID, Name,Sex, Designation, Salary, DOJ
iv) Degree = Total number of columns = 6
v) Cardinality =Total number of rows = 3
Codd proposed 13 rules for relational database management system, which are
popularly known as Codd’s 12 rule : These rules are as follows –
Rule 0 : This rule states for a database to be relational, it must use its relational capabilities
to manage the database.
Rule 1 : The Information rule - All information in an RDBMS is represented logically only
by storing the values in tables.
Rule 2 : The Guaranteed Access rule - Each item of data in an RDBMS is guaranteed to be
logically accessible by specifying the table name, primary key value, and column name.
Rule 3 : The Systematic Treatment of Null Values rule - Null values are supported in a
fully relational DBMS for representing missing information or inapplicable information in
a systematic way which is independent of the data type.
Rule 4 : The Dynamic Online Catalog Based on the Relational Model rule - Database
dictionary which is called as catalog-is the structure description of the complete Database
and it must be stored online. This Catalog must be governed by same rules as rest of the
database. The same query language should be used on catalog as used to query database.
Rule 5 : The Comprehensive Data Sublanguage rule - At least one well structured, well-
defined language must be there which can access all the data present in the database.
Rule 6 : The View Updating rule - All views of the data which are theoretically updatable
must be updatable in practice by the DBMS.
Rule 7 : Relational level operation - The High-level Insert, Update, and Delete rule: There
must be insert, delete and update operations at each level of relations.
Rule 8 : The Physical Data Independence rule - Physical storage should not matter the
system. Whenever any changes are made in either storage representations or access
methods then it should not affect the application.
Rule 9 : The Logical Data Independence rule - If any changes are made in table structure
then the logical view of the user should not get affected. Fpr Rule example - if a table is
split into two tables internally, the view of the table to the user should be an entire table
and not the split tables.
Rule 10 : The Integrity Independence rule - The Integrity constraints must be defined by
the RDBMS stored in the system and it should not be enforced by the external application
programs.
Review Questions
1. One of the rule designed by Codd's for good relational database management system is
integrity independence, which states that all integrity constraints can be independently
modified without the need of any change in the application. Justify the significance of rule in
relational database management system. SPPU : Aug.-17, In Sem, Marks 5
2. Twelve rules are proposed by codd, which according to him, a database must obey in order to be
regarded as a true relational database. One of the rule is comprehensive data sub language rule.
A database can only be accessed using a language having linear syntax that supports data
definition, data manipulation and transaction management operations. Explain in brief above
rule. Also state its significance. SPPU : Oct.-19, In Sem, Marks 5
4.4 Keys
Keys are used to specify the tuples distinctly in the given relation.
Various types of keys used in relational model are – Superkey, Candidate Keys,
primary keys, foreign keys. Let us discuss them with suitable example
1) Super Key(SK) :
It is a set of one or more attributes within a table that can uniquely identify each record
within a table. For example – Consider the Student table as follows –
Reg No. Roll No Phone Name Marks
Clearly using the (RegNo) and (RollNo,Phone,Name) we can identify the records
uniquely but (Name, Marks) of two students can be same, hence this combination not
necessarily help in identifying the record uniquely.
2) Candidate Key(CK) :
The candidate key is a subset of superset. In other words candidate key is a single
attribute or least or minimal combination of attributes that uniquely identify each record
in the table. For example - in above given Student table, the candidate key is RegNo,
(RollNo,Phone). The candidate key can be
Thus every candidate key is a superkey but every superkey is not a candidate key.
3) Primary Key(PK) :
The primary key is a candidate key chosen by the database designer to identify the
tuple in the relation uniquely. For example – Consider the following representation of
primary key in the student table
Other than the above mentioned primary key, various possible primary keys can be
(RollNo), (RollNo,Name), (RollNo, Phone)
The relation among super key, candidate key and primary can be denoted by
Candidate Key = Super Key – Primary Key
Rules for Primary Key
i) The primary key may have one or more attributes.
ii) There is only one primary key in the relation.
iii) The value of primary key attribute can not be NULL.
iv) The value of primary key attribute does not get changed.
4) Alternate key :
The alternate key is a candidate key which is not chosen by the database designer to
uniquely identify the tuples. For example –
5) Foreign key :
Foreign key is a single attribute or collection of attributes in one table that refers to the
primary key of other table.
Thus foreign keys refer to primary key.
The table containing the primary key is called parent table and the table containing
foreign key is called child table.
Example -
From above example, we can see that two tables are linked. For instance we could
easily find out that the ‘Student CCC has opted for ComputerSci course’
Constraints mean some rules or restrictions that are set on the database.
There are three main types of constraints.
1. Domain Constraint
2. Key Constraint or NULL Constraint
3. Integrity Constraint
i) Entity Integrity Constraint
ii) Referential Integrity Constraint
1. Domain Constraint
The data type of domain includes string, character, integer, time, date, currency, etc.
The value of the attribute must be available in the corresponding domain.
Keys are used to identify particular record from the table. Primary key is normally
used to identify the record uniquely.
The above relation does not satisfy key constraint as the primary key is not having
unique value.
3. Integrity Constraint
Integrity constraints are rules that are to be applied on database columns to ensure
the validity of data.
For example -
i) The Employee ID and Department ID must consist of two digits.
ii) Every Employee ID must start with letter.
i) Entity Integrity Constraint
This rule states that “In the relations, the value of attribute of primary key can not
be null”.
The NULL represents a value for an attribute that is currently unknown or is not
applicable for this tuple. The Nulls are always to deal with incomplete or
exceptional data.
The primary key value helps in uniquely identifying every row in the table. Thus if
the users of the database want to retrieve any row from the table or perform any
action on that table, they must know the value of the key for that row. Hence it is
necessary that the primary key should not have the NULL value.
For example -
In above relation, the registration no. R555 is not existing still if it is present in the
course table, then we say that it is not following referential integrity constraint.
Review Question
1. Explain the concepts of referential integrity constraint and entity integrity constraint with
example. SPPU : May-18, Dec.-19, End Sem, Marks 5
Now if we want to insert a record 5,EEE,50000 for the DeptID 101, then again there
will be repletion of information about DeptID, DeptName and DeptLoc i.e.
(101,XYZ,Pune). That means if we want to perform some operation (insertion, updation,
deletion) on the relational schema then it should not cause repetition of information.
The above scenario indicates bad database design.
Inability to represent information is a condition where a relationship exists among
only a proper subset of the attributes in a relation. This is bad relational database design
because all the unrelated attributes must be filled with null values otherwise a tuple
without the unrelated information cannot be inserted into the relation.
Review Question
1) Redundant storage : Note that the information about DeptID, DeptName and
DeptLoc is repeated.
2) Update anomalies : In above table if we change DeptLoc of Pune to Chennai, then
it will result inconsistency as for DeptID 101 the DeptLoc is Pune. Or otherwise, we
need to update multiple copies of DeptLoc from Pune to Chennai. Hence this is an
update anomaly.
3) Insertion anomalies : For above table if we want to add new tuple say
(5, EEE,50000) for DeptID 101 then it will cause repeated information of (101,
XYZ,Pune) will occur.
4) Deletion anomalies : For above table, if we delete a record for EmpID 4, then
automatically information about the DeptID 102, DeptName PQR and DeptLoc
Mumbai will get deleted and one may not be aware about DeptID 102. This causes
deletion anomaly.
4.9 Normalization
SPPU : Dec.-17, Marks 5
Normalization is the process of reorganizing data in a database so that it meets two
basic requirements :
1) There is no redundancy of data (all data is stored in only one place) and
2) Data dependencies are logical (all related data items are stored together)
1 AAA 11111
22222
2 BBB 33333
3 CCC 44444
55555
As there are multiple values of phone number for sid 1 and 3, the above table is not in
1NF. We can make it in 1NF. The conversion is as follows -
sid sname Phone
1 AAA 11111
1 AAA 22222
2 BBB 33333
3 CCC 44444
3 CCC 55555
Review Question
1. Suggest and explain three different techniques to achieve 1NF using suitable example.
1 AAA Mumbai
2 BBB Pune
3 CCC Gandhinagar
Here
Roll ->Name hold
But
Name->City does not hold
In above table, student roll number is unique hence each student’s name and city
can be uniquely identified using his roll number.
But using name we cannot uniquely identify his/her city because there can be same
names of the students. Similarly using city name we can not identify the student
uniquely. As in the same city may belong to multiple students.
Another example -
Consider a relation in which the roll of the student and his/her name is stored as
follows :
R N
1 AAA
2 BBB
3 CCC
4 DDD
5 EEE
Here, R->N is true. That means the functional dependency holds true here. Because for
every assigned RollNuumber of student there will be unique name. For instance : The
name of the Student whose RollNo is 1 is AAA. But if we get two different names for the
same roll number then that means the table does not hold the functional dependency.
Following is such table -
R N
1 AAA
2 BBB
3 CCC
1 XXX
2 YYY
In above table for RollNumber 1 we are getting two different names - “AAA” and
“XXX”. Hence here it does not hold the functional dependency.
Trivial FD : The functional dependency A->B is trivial if B is a subset of A.
For example (A,B}->A
Non Trivial FD : The functional dependency A->B is non trivial if B is not a subset
of A.
For example {A,B}->C
Example 4.11.1 For the given below relation R(A,B,C,D,E) and its instance, check whether
FDs given hold or not. Give reasons.
i) A->B ii) B->C iii) D->E iv) CD->E
A B C D E
a1 b1 c1 d1 e1
a1 b2 c1 d1 e1
a2 b2 c1 d2 e3
a2 b3 c3 d2 e2
Step 2 : As
A -> B (Refer step 1)
B -> D (given)
A -> D (transitivity rule)
Step 3 :
A -> CD because A -> C and A -> D (From step 1 and Step 2 applying
union rule)
Step 4 :
CD -> E (given)
A -> E (transitive rule as A->CD, CD->E
hence A->E)
Step 5 :
Since A → A, we have (reflexive)
A → ABCDE from the above steps (union)
Step 6 :
Since E → A, E → ABCDE (transitive)
Step 7 :
Since CD → E, CD → ABCDE (transitive)
Step 8 :
Since B → D and BC → CD, BC → ABCDE (augmentative, transitive)
Step 9 :
Also, C → C, D → D, BD → D
Thus any functional dependency with A, E, BC, or CD on the left hand side of the
arrow is in F+
Example 4.11.4 Give Armstrong’s axioms and using it find the closure of following FD set.
Solution :
Step 1 : A -> BC
∴ A -> B and A -> C (decomposition)
So we add A, B, C in closure set
Step 2 : E -> CF
∴ E -> C and E -> F (decomposition)
1) Finding (E-ID)+ means finding the closure. In this process we try to find out, all the
attributes that can be derived from E-ID.
As E-ID->E-NAME, E-ID->E-CITY, E-ID->E-STATE, We add E-NAME, E-ID,
E-CITY, E-STATE to (E-ID)+
As E-ID->E-CITY, E-CITY->E-STATE, we add E-STATE to (E-ID)+
∴ (E-ID)+ = {E-ID, E-NAME, E-CITY, E-STATE)
2) E-NAME derives no rule. Hence (E-NAME)+ = {E-NAME}
Example 4.11.7 Give R = {A,B,C,G,H,I}. The following set F of functional dependencies holds
Step 3 : CG -> I, hence add I to the set of AG+. Also add G to the set.
Thus (AG)+ = {A,B,C,G,H,I} = Relation R
Hence (AG)+ is a candidate key.
Example 4.11.8 Compute the closure of R(A,B,C,D,E) with the following set of functional
dependencies A -> BC, CD -> E, B -> D, E -> A
List the candidate keys of R
Solution :
Example 4.11.9 Consider schema R = (A,B,C,G,H,I) and the set F of functional dependencies
{A -> B, A -> C, CG -> H, CG -> I, B -> H}. Use (F)+ Prove (AG)+ -> I
Solution :
Step 1 : As A -> B
B -> H
∴ A -> H (Transitivity rule)
Step 2 : CG -> H
CG -> I
∴ CG -> HI (Union rule)
Step 3 : A -> C
CG -> I
AG -> I (Pseudo transitive rule)
Thus AG -> I is proved
(F)+ = {A -> B, A -> C, CG -> H, CG -> I, B -> H, A -> H, CG -> HI, AG -> I}
Review Questions
1. Explain in brief with suitable example full functional dependency and partial dependency.
SPPU : Oct.-19, In Sem, Marks 3
2. What is the impact of insert, update and delete anomaly on overall design of database ? How
normalization is used to remove these anomalies ? SPPU : May-18, End Sem, Marks 5
Step 1 : We will first check if all the FDs of FD1 are present in FD2
A -> B is present in FD1. A -> BC is in FD2, that also means
i.e D -> A, D -> C by decomposition rule. As A -> B, then by transitivity rule D -> A,
A -> B, D -> B
D -> E is given
(D)+ = {A,B,C,D,E}
Step 2 : We will first check if all the FDs of FD2 are present in FD1
(D)+ = {A,B,C,D,E}
Thus from Step 1 and Step 2, FD2 ⊃ FD1 and FD1 ⊃ FD2. Hence both the sets are
equivalent.
Example 4.12.2 Consider two sets of functional dependency.
F = {A -> C, AC -> D, E -> AD, E -> H} and G = {A -> CD, E -> AH}. Are they equivalent ?
Solution : We will find the FDs of both F and G and then check for F and G ⊃ FD2 and
G ⊃ F.
Step 1 : For F
Using G functional dependencies -
(A)+ = {A,C,D} As A -> CD is in G
(AC)+ = {A,C,D} As A -> CD is in G
(E)+ = {A,C,D,E,H} As E -> AH, A -> CD is in G
Using F functional dependencies -
(A)+ = {A,C,D} As A -> C and AC -> D is in F
(AC)+ = {A,C,D} AC -> D is in F
(E)+ = {A,C,D,E,H} As E -> AD, E -> H and A -> C is in F
Step 2 : For G
Using F functional dependencies -
(A)+ = {A,C,D} As A -> C and AC -> D is in F
(E)+ = {A,C,D,E,H} As E -> AD, E -> H is in F
Using G functional dependencies -
(A)+ = {A,C,D} As A -> CD is in G
(E)+ = {A,C,D,E,H} As E -> AH and A -> CD is in G
Step 1 : For F
Using G functional dependencies -
(A)+ = {A,B,C}
(AB)+ = {A,B,C}
(D)+ = {D,A,C,E,B}
Using F functional dependencies -
(A)+ = {A,B,C}
(AB)+ = {A,B,C}
(D)+ = {D,A,C,E,B}
Step 2 : For G
Using F functional dependencies –
(A)+ = {A,B,C}
(D)+ = {D,A,C,E,B}
Using G functional dependencies -
(A)+ = {A,B,C}
(D)+ = {D,A,C,E,B}
Minimal cover
Formal definition : A minimal cover for a set F of FDs is a set G of FDs such that :
1) Every dependency in G is of the form X -> A, where A is a single attribute.
2) The closure F+ is equal to the closure G+.
3) If we obtain a set H of dependencies from G by deleting one or more dependencies
or by deleting attributes from a dependency in G, then F+ ≠ H+.
repeat
Use the union rule to replace any dependencies in Fc of the form
1 1 and 1 2 and 1 1 2
Find a functional dependency in Fc with an extraneous attribute either in
or in .
/* The test for extraneous attributes is done using Fc, not F */
If an extraneous attribute is found, delete it from in Fc .
until (Fc does not change)
Example 4.12.4 Consider the following functional dependencies over the attribute set
R(ABCDE) for finding minimal cover FD = {A -> C, AC -> D, B -> ADE}.
Solution :
Step 1 : Split the FD such that R.H.S contain single attribute. Hence we get
A -> C
AC -> D
B -> A
B -> D
B -> E
Step 2 : Find the redundant entries and delete them. This can be done as follows -
For A -> C : We find (A)+ by assuming that we delete A -> C temporarily. We get
(A)+={A}. Thus from A it is not possible to obtain C by deleting A -> C. This means
we can not delete A -> C.
For AC -> D : We find (AC)+ by assuming that we delete AC -> D temporarily. We
get (AC)+= {AC}. Thus by such deletion it is not possible to obtain D. This means we
can not delete AC -> D.
For B -> A : We find (B)+ by assuming that we delete B -> A temporarily. We get
(B)+= {BDE}. Thus by such deletion it is not possible to obtain A. This means we can
not delete B -> A.
For B -> D : We find (B)+ by assuming that we delete B -> D temporarily. We get
(B)+= {BEACD}. This shows clearly that even if we delete B -> D we can obtain D.
This means we can delete B -> A. Thus it is redundant.
For B -> E : We find (B)+ by assuming that we delete B -> E temporarily. We get
(B)+= {BDAC}. Thus by such deletion it is not possible to obtain E. This means we
can not delete B->E.
To summarize we get now
A -> C
AC -> D
B -> A
B -> E
Thus R.H.S gets simplified.
Step 3 : The simplified L.H.S. and R.H.S can be combined together to form
A -> CD
B -> AE
This is a minimal cover or canonical cover of functional dependencies.
Example 4.12.5 A relation R(A,C,D,E,H) satisfies the following FDs A -> C, AC -> D,
E -> AD, E -> H. Find the canonical cover for this set of FD’s.
Solution : For obtaining canonical cover we have to find the redundant entries from both
LHS and RHS and eliminate them.
Step 1 : Suppose we minimize LHS first, then go through each production rule one by
one considering LHS.
A -> C , Keep it as it is.
AC -> D, Here A -> C and A -> D, So we remove A -> C , hence A -> D is kept by
eliminating C from LHS.
E -> AD, keep it as it is as E is a single attribute at LHS.
E -> H, keep it as it is
Solution :
AE -> B
A -> D
D -> E
D -> F
For A -> D, we will compute(A)+ under (G - (A -> D))
(A)+ = {AEBC}. As D is not present in (A)+, hence we can not eliminate A -> D. The
grammar is
B -> C
AE -> B
A -> D
D -> E
D -> F
For D -> E, compute (D)+ under (G - (D -> E))
(D)+ = {DF}. As E is not present in (D)+, We cannot remove D -> E
For D -> F, compute (D)+ under (G-(D -> F))
(D)+ = {DE}. As F is not present in (D)+, We cannot remove D -> F. Finally the grammar
is
B -> C
AE -> B
A -> D
D -> E
D -> F
Now consider BD -> C, We can replace this by B -> C and eliminate D, as D -> B is
present.
Similarly consider AE -> F. But as we cannot replace it either by A->F or E->F. So it is
not redundant.
The minimal cover is {A->D, D->B. D->G, B->C, AE->F}.
We can decompose the above relation Schema into two relation schemas as Employee
(Eid, Ename, Age, City, Salary) and Department (Deptid, Eid, DeptName) as follows -
Employee Table
Department Table
Hence, the above table can be decomposed into two Schema S and T as follow :
Schema S Schema T
3) Checking some dependencies may require joining the instances of the decomposed
relations.
4) There may be loss of information during decomposition.
Example 4.14.1 Consider the following relation R(A, B, C, D)and FDs A->BC, is the
decomposition of R into R1(A, B, C), R2(A, D). Check if the decomposition is lossless join or
not.
Solution :
Step 1 : Here Att(R1) ∪ Att(R2) = Att(R) i.e R1(A,B,C) ∪ R2(A,D) = (A,B,C,D) i.e R.
Thus first condition gets satisfied.
Step 2 : Here R1 ∩ R2 = {A}. Thus Att(R1) ∩ Att(R2) ≠ Φ. Here the second condition gets
satisfied.
Step 3 : Att(R1) ∩ Att(R2) -> {A}. Now (A)+ = {A,B,C} i.e. attributes of R1. Thus the third
condition gets satisfied.
This shows that the given decomposition is a lossless join.
Example 4.14.2 Consider the following relation R(A, B, C, D, E, F) and FDs A->BC, C->A,
D->E, F->A, E->D is the decomposition of R into R1(A, C, D), R2(B, C, D) and
R3 (E, F, D). Check for lossless.
Solution :
Step 1 : R1 ∪ R2 ∪ R3 = R. Here the first condition for checking lossless join is satisfied as
(A,C,D) ∪ (B,C,D) ∪ (E,F,D) = {A,B,C,D,E,F} which is nothing but R.
Step 2 : Consider R1∩ R2 = {CD} and R2∩R3 = {D}. Hence second condition of
intersection not being gets satisfied.
Step 3 : Now, consider R1(A, C, D) and R2(B, C, D). We find R1∩R2 = {CD}
(CD)+ = {ABCDE} attributes of R1 i.e.{A, C, D}. Hence condition 3 for checking
lossless join for R1 and R2 gets satisfied.
Solution :
Step 1 : Here we need to assume some data for the attributes A, B, C, D, and E. Using
this data we can represent the relation as follows -
Relation R
A B C D E
a 1 x p q
b 2 x r s
Relation R1 = (A,B,C)
A B C
a 1 x
b 2 x
Relation R2 = (C,D,E)
C D E
x p q
x r s
Step 2 : Now we will join these tables using natural join, i.e. the join based on common
attribute C. We get R1 ⋈ R2 as
A B C D E
Here we get
a 1 x p q more rows
or tuples
a 1 x r s
than original
b 2 x p q relation R
b 2 x r s
Review Question
Step 3 : Let us find (F1)+ for relation R1 and (F2)+ for relation R2
R1(A,C) R2(B,C)
Step 4 : We will eliminate all the trivial relations and useless relations. Hence we can
obtain R1 and R2 as
R1(A,C) R2(B,C)
Solution :
Step 2 : We will find (F1)+, (F2)+, (F3)+ for relations R1(A,B) , R2(B,C) and R3(B,D) as
follows -
R1(A,B) R2(B,C) R3(B,D)
and it’s non Trivial it’s non Trivial B->C->D and it’s non
Step 3 : We will eliminate all the trivial relations and useless relations. Hence we can
obtain R1 ∪ R2 ∪ R3 as
R1(A,B) R2(B,C) R2(B,D)
C->B D->B
Solution :
Step 1 : Construct a table with six columns for given six attributes i.e. X, Y, W, Z, P, Q and
two rows for given two relation i.e. R1 and R2.
X Y W Z P Q
R1
R2
R2 X Y 2W Z P Q
Step 3 :
i) Considering XY W, we check if the two rows of the table have the same value
under the columns XY that make up the determinant of the FD. Since the rows do
not have identical values, the table will remain unchanged and we repeat step 3 by
considering another FD.
ii) Considering XW P, we check if the two rows of the table have the same value
under the columns XW that make up the determinant of the FD. Since the rows do
not have identical of values, the table will remain unchanged and we repeat step 3
by considering another FD.
iii) Considering PQ Z, we check if the two rows of the table have the same value
under the columns PQ that make up the determinant of the FD. Since the rows R1
and R2 have values of P and Q under the columns PQ. Therefore, we need to
equate all the corresponding entries for the rows under column Z. The values in
column Z are already equal no changes are necessary Repeat step 3 again.
iv) Considering XY Q, we check if the two rows of the table have the value under
the columns XY that make up determinant of the FD. Since rows do not have
identical values, the table will remain unchanged. Now, there are no more FDs to
consider.
Step 4 : Since there is no row in the table that has all Φ in it’s entries the decomposition is
lossy. That is original table cannot be recovered from the join of relations R1 and R2.
Example 4.15.4 Suppose we decompose the scheme R=(A,B,C,D,E) into (A,B,C) and (A,D,E).
Show that this decomposition is the lossless decomposition if following functional
dependencies hold : A->BC,CD->E, B->D
Show that decomposition is dependency preserving decomposition.
Solution :
Step 1 : Construct table with five columns for given five attributes i.e. A, B, C, D, E and
two rows for given two relations i.e. R1 (A, B, C) and R2 (A, D, E).
A B C D E
R1
R2
Step 2 : The attributes of the scheme of R1 are A, B, C. Therefore, we place A, B and C
under these columns respectively. The remaining entries of this row are filled with 1D
and 1E. Same as for R2 have attributes A, D, E. Therefore, we place A, D and E under
these columns respectively. The remaining entries of this row are filled with 2B and 2C.
A B C D E
R1 A B C 1D 1E
R2 A 2B 2C D E
Step 3 :
i) Considering A BC we check if the two rows of the table have the same value
under the columns that make up the determinant of FD. Rows R1 and R2 has values
A under column A. Therefore, we need to equate all the corresponding entries for
these rows under columns B and C.
Since entry under column B is B (for row R1) and column C is C (for row R2).
A B C D E
R1 A B C 1D 1E
R2 A B C D E
ii) Considering CD E, we check for rows that have the same value in the columns C
and D. Here, rows do not same values, the table remain unchanged and we repeat
step 3 by another FD.
iii) Considering B D, we check for rows that have the same value in the columns B
here rows have same values B under the column B. Therefore, we need to equate
all the corresponding entries for these rows under column D. Since entry under
column D is D for row R1.
A B C D E
R1 A B C D 1E
R2 A B C D E
decomposition is lossless.
Before understanding the second normal form let us first discuss the concept of partial
functional dependency and prime and non prime attributes.
1 AAA 101 C
3 CCC 101 C
This table is not in 2NF. For converting above table to 2NF we must follow the
following steps -
Step 2 : Here sname and sid are associated similarly cid and cname are associated with
each other. Now if we delete a record with sid = 2, then automatically the course C++ will
also get deleted. Thus,
sid->sname or cid->cname is a partial functional dependency, because {sid,cid} should
be essentially a candidate key for above table. Hence to bring the above table to 2NF we
must decompose it as follows :
Student Here candidate key is
(sid, cid)
and
sid sname cid (sid, cid)->sname
1 AAA 101
2 BBB 102
3 CCC 101
4 DDD 103
Course
4627 38 60
3214 20 20.00
4627 30 60.20
Item lines
Order no. Order date
Item code Quantity Price/Unit
The above table has insertion, deletion and update anomalies. For instance - if we
delete order no. 1886, then the item code 4629 gets lost. Similarly if we update 4627,
then all instances of 4627 need to be changed.
We need to convert 2NF if it is in 1NF. The non-key attributes are functionally
dependent on key attribute and if there is a composite key then no non-key
attribute is functionally depend on one part of the key.
The table can be converted to 2NF as follows -
Orders
OrderNo OrderDate
1456 26-12-1999
1886 04-03-1999
1788 04-04-1999
Order details
OrderNo ItemCode Qty
1456 3687 52
1886 4629 45
1788 4627 40
Prices
ItemCode Price/Unit
3687 50.4
4627 60
3214 20
4629 20.25
Review Question
1. Explain why database normalization is required for good relational database design ? Explain
with example requirements of second normal form. SPPU : Oct.-19, In Sem, Marks 7
4.17 Third Normal Form (3NF) SPPU : Oct.-18, 19, Aug.-17, Dec.-18, Marks 7
Before understanding the third normal form let us first discuss the concept of
transitive dependency, super key and candidate key.
101 1 AAA
102 2 BBB
103 3 CCC
104 4 DDD
Superkeys
{RegID}
{RegID, RollNo}
{RegID, Sname}
{RollNo, Sname}
{RegID, RollNo, Sname}
Candidate keys
{RegID}
{RollNo}
Third normal form
A table is said to be in the third normal form when,
i) It is in the second normal form.(i.e. it does not have partial functional dependency).
ii) It doesn't have transitive dependency.
Or in other words
In other words 3NF can be defined as : A table is in 3NF if it is in 2NF and for each
functional dependency
X-> Y
at least one of the following conditions hold :
i) X is a super key of table.
ii) Y is a prime attribute of table.
For example : Consider following table Student_details as follows -
Here
1 AAA 11111
2 BBB 22222
3 CCC 33333
4 DDD 44444
5 EEE 55555
Zip
zipcode cityname state
Solution : Let,
A DE (given)
A D, A E (decomposition rule)
As D I J, A I J
Using union rule we get
A DEIJ
As A A
we get A ADEIJ
Using augmentation rule we compute AB
AB ABDEIJ
But AB C (given)
AB ABCDEIJ
B F (given) F GH B GH (transitivity)
AB AGH is also true
Similarly AB AF ∵ B F (given)
Thus now using union rule
AB ABCDEFGHIJ
AB is a key
The table can be converted to 2NF as
R1 = (A, B, C)
R2 = (A, D, E, I, J)
R3 = (B, F, G, H)
Example 4.17.2 A software contract and consultancy firm maintains details of all the various
projects in which its employees are currently involved. These details comprise :
• Employee number
• Employee name
• Date of birth
• Department code
• Department name
• Project code
• Project description
• Project supervisor
Assume the following :
• Each employee number is unique.
• Each department has a single department code.
• Each project has a single code and supervisor.
• Each employee may work on one or more projects.
• Employee names need not necessarily be unique.
• Project code, project description and project supervisor are repeating fields.
Normalise this data to third normal form.
Solution :
Un-Normalized Form
Employee Number, Employee Name_Date of Birth_Department Code_Department Name_Project
Code_Project Description_Project Supervisor
1NF
Employee Number, Employee Name_Date of Birth
Department Code, Department Name
Employee Number, Project Code, Project Description_Project Supervisor
2NF
Employee Number, Employee Name_Date of Birth_Department Code_Department Name
Employee Number,Project Code,
Project Code, Project Description,Project Supervisor
3NF
Employee Number, Employee Name_Date of Birth_*Department Code
Department Code, Department Name
Employee Number, Project Code
Project Code, Project Description, Project Supervisor
Example 4.17.3 What is normalization ?Normalize below given relation upto 3NF
STUDENT.
Solution : For converting the given schema to first normal form, we will arrange it in such
a way that have each tuple contains single record. For that purpose we need to split the
schema into two tables namely Student and Projects.
1NF
Student
Projects
2NF
Student
StudID StudName Pincode City
Project
CourseDetails
C103 Programming C
3NF
There was a transitive dependency in 2NF tables because city is associated with
student ID and city depends upon zip code. Hence the transitive dependency is removed
to covert table into 3NF. The required 3NF schema is as below -
Student
StudID StudName Pincode
Student_Address
Pincode City
326201 Surat
325456 Pune
Project
StudID ProjectID ProjName CourseID
CourseDetails
CourseID Course Content
C103 Programming C
Example 4.17.4 What is the need for normalization ? Consider the relation : Emp-proj = {ssn,
Pnumber, Hours, Ename, Pname, Plocation}
Assume {ssn,Pnumber} as primary key.
The dependencies are:
{ssn,Pnumber}->Hours
Ssn-> Ename
Pnumber ->{Pname,Plocation}
Normalize the above relation to 3NF.
Solution : Need for normalization - Refer section 4.9.
Consider the given dependencies
(1) {ssn,Pnumber}->Hours
(2) ssn-> Ename
(3) Pnumber ->{Pname,Plocation}
The dependencies 2 and 3 represents the partial dependency. Hence we convert the
relation into second normal form by splitting the given Emp-proj into three relations
Emp = {ssn, Ename}
Proj = {Pnumber, Pname, Plocation}
Works = {ssn, Pnumber, Hours}
Example 4.17.5 Consider the following relation for CARSALE(CAR-NO,Date-Sold,Salesman-
no, Commission, Discount).
Assume a car can be sold by multiple salesman and hence primary is (CAR-NO,Salesman-
no)
Additional dependencies are
Date_Sold ->Discount
Salesman_no ->Commission
i) Is this relation in 1NF, 2NF, 3NF ? Why and Why not ?
ii) How would you normalize this completely ?
Solution :
First normal form : As the relation have no multivalued attributes or nested relations,
the given relation is in 1st normal form.
Second normal form : This relation is not in second normal form because the attribute
commission is dependent on part of primary key Salesman-no.
Third normal form : This relation is not in third normal form because firstly it is not in
2nd normal form and there should be transitive dependency of a nonkey attribute on
primary key.
(CAR-No, Salesman-no) ->Date_sold->Discount
(ii) To normalize this relation we will decompose it into
R1={CAR-No, Salesman-no, Date_sold}
R2={Date_sold, Discount}
R3={Salesman-no, commission}
The functional dependency is as follows -
F1={(CAR-No, Salesman-no)→Date_sold}
F2={Date_sold→Discount}
F3={Salesman-no→commission}
Example 4.17.6 Normalize the below relation upto 3NF
M1 D1 L1 T1
M1 D1 L1 T2
M2 D1 L1 T1
M2 D1 L1 T3
M3 D1 L2 T4
M4 D2 L3 T1
M4 D2 3 T5
M5 D2 L4 T6
Solution : The given relation is already in 1st normal form. But it has Insert, delete and
update anomalies. Because -
1) Insert anomalies : We can not add a module(M) with no texts(T).
M1 D1 L1
M2 D1 L1
M3 D1 L2
M4 D2 L3
M5 D2 L4
Table 2b
Module Text
M1 T1
M1 T2
M2 T1
M2 T3
M3 T4
M4 T1
M4 T5
M5 T6
Step 3 : The table 2a has Insert, Delete and Update anomalies. Because -
2) UPDATE anomalies : To change the department for L1 we must alter two rows.
Hence, to eliminate these anomalies, we decompose table 2a into two tables and
convert it to third normal form.
Step 4 : Hence we get
Table 3a
Lecturer Dept.
L1 D1
L2 D1
L3 D2
L4 D2
Table 3b
Module Lecturer
M1 L1
M2 L1
M3 L2
M4 L3
M5 L4
Step 5 : Thus now the complete relation is decomposed into three tables and it is in third
normal form. It is summarized as below
Table 3a Table 3b Table 2b
Lecturer Dept. Module Lecturer Module Text
L1 D1 M1 L1 M1 T1
L2 D1 M2 L1 M1 T2
L3 D2 M3 L2 M2 T1
L4 D2 M4 L3 M2 T3
M5 L4 M3 T4
M4 T1
M4 T5
M5 T6
Consider above schema, check whether it is in 3NF, if not justify and propose the schema
in 3NF.
SPPU : Oct.-18, In Sem, Marks 5
Solution : The given schema is not in 3NF because there exists following transitive
dependencies.
Because city is associated with Stud_id and city depends upon the zip code. When this
dependency is removed then the table will be in 3NF. It is as follows –
Student
Stud_id Stud_name Zip
Student_address
Zip City
To convert the above schema to third normal form we need to decompose the schema
into different relations –
Student_info
Exam_info
Review Questions
1. Explain what is normalization ? Explain with example requirements of Third Normal Form.
SPPU : Aug.-17, In Sem, Marks 5
2. Explain why Database normalization is required for good relational database design ? Explain
with example requirements of different normal forms like 1NF, 2NF and 3NF.
SPPU : Dec.-18, End Sem, Marks 5
Boyce and Codd Normal Form is a higher version of the Third Normal form. This
form deals with certain type of anomaly that is not handled by 3NF.
A 3NF table which does not have multiple overlapping candidate keys is said to be in
BCNF.
Or in other words,
For a table to be in BCNF, following conditions must be satisfied :
i) R must be in 3rd Normal Form
ii) For each functional dependency ( X → Y ), X should be a super key. In simple words
if Y is a prime attribute then X can not be non prime attribute.
For example - Consider following table that represents that a student enrollment for
the course -
Enrollment table
sid Course Teacher
1 C Ankita
1 Java Poonam
2 C Ankita
3 C++ Supriya
4 C Archana
Student
sid Teacher
1 Ankita
1 Poonam
2 Ankita
3 Supriya
4 Archana
Course
Teacher Course
Ankita C
Poonam Java
Ankita C
Supriya C++
Archana C
Step 1 : We will first find out the candidate key from the given FD.
(AB)+ = {ABCD} = R
(BC)+ = {ABCD} = R
(AC)+ = {AC} ≠ R
There is no involvement of D on LHS of the FD rules. Hence D can not be part of any
candidate key. Thus we obtain two candidate keys (AB)+ and (BC)+. Hence
prime attributes = {A,B,C}
Non prime attributes = {D}
Step 2 : Now, we will start checking from reverse manner, that means from BCNF, then
3NF, then 2NF.
Step 3 : For R being in BCNF for X->Y the X should be candidate key or super key.
From above FDs consider C->D in which C is not a candidate key or super key. Hence
given relation is not in BCNF.
Step 4 : For R being in 3NF for X->Y either i) the X should be candidate key or super key
or
ii) Y should be prime attribute. (For prime and non prime attributes refer step 1)
o For AB->C or AB->D the AB is a candidate key. Condition for 3NF is satisfied.
o Consider C->A. In this FD the C is not candidate key but A is a prime attribute.
Condition for 3NF is satisfied.
o Now consider B->D. In this FD, the B is not candidate key, similarly D is not a
prime attribute. Hence condition for 3NF fails over here.
Hence given relation is not in 3NF.
Solution :
Step 2 : For R being in BCNF for X->Y the X should be candidate key or super key.
Solution :
Step 1 : We will first find out the candidate keys for given relation R
(ACD)+ = {A,B,C,D,E}
(BCD)+ = {A,B,C,D,E}
(CDE)+ = {A,B,C,D,E}
Step 2 : Let A->B, the ACD is candidate key and A is a partial key, B is a prime
attribute(i.e. it is also part of candidate key). Hence A->B is not a partial functional
dependency.
Similarly in BC->E and ED->A,
E and A are prime-attributes and hence both are not partial functional dependencies.
Hence R is in 2NF.
Step 4 : For R being in BCNF for X->Y the X should be candidate key or super key.
The table is not in BCNF, none of A, BC and ED contain a key.
Example 4.18.4 A college maintains details of its lecturers' subject area skills. These details
comprise :
• Lecturer number
• Lecturer name
• Lecturer grade
• Department code
• Department name
• Subject code
• Subject name
• Subject level
Assume that each lecturer may teach many subjects but may not belong to more than one
department.
Subject code, subject name and subject level are repeating fields.
Normalise this data to third normal form.
Solution :
Unnormalized form
Lecturer Number, Lecturer Name_Lecturer Grade_Department Code,Department Name_Subject
Code, Subject Name_Subject Level
1NF
2NF
Lecturer Number _Lecturer Name _Lecturer Grade _Department Code _Department Name
3NF
Example 4.18.5 Prove that any relational schema with two attributes is in BCNF.
Solution : Here, we will consider R={A,B} i.e. a relational schema with two attributes. Now
various possible FDs are A->B, B->A.
From the above FDs
o Consider A->B in which A is a candidate key or super key. Condition for BCNF is
satisfied.
o Consider B->A in which B is a candidate key or super key. Condition for BCNF is
satisfied.
o Consider both A->B and B->A with both A and B is candidate key or super key.
Condition for BCNF is satisfied.
o No FD holds in relation R. In this {A,B} is candidate key or super key. Still
condition for BCNF is satisfied.
This shows that any relation R is in BCNF with two attributes.
Example 4.18.6 Prove the statement “Every relation which is in BCNF is in 3NF but the
converse is not true.”
In other words 3NF can be defined as : A table is in 3NF if it is in 2NF and for each
functional dependency X-> Y
at least one of the following conditions hold :
iii) X is a super key of table
iv) Y is a prime attribute of table
For a relation to be in BCNF
1) It should be in 3NF
2) A 3NF table which does not have multiple overlapping candidate keys is said to be
in BCNF.
For proving that the table can be in 3NF but not in BCNF consider Following relation
R(Student, Subject, Teacher) . Consider following are FDs
(Subject, Student)-> Teacher
Because subject and student combination gives unique teacher.
Teacher -> Subject
Because each teacher teaches only Subject.
(Teacher, Student)->Subject
So, this relation is in 3NF as every non-key attribute is non-transitively fully
functional dependent on the primary key.
But it is not in BCNF. Because this is a case of overlapping of candidate keys
because there are two composite candidate keys :
o (Subject, Student)
o (Teacher, Student)
And student is a common attribute in both the candidate keys.
So we need to normalize the above table to BCNF. For that purpose we must set
Teacher to be a candidate key
The decomposition of above takes place as follows
R1(Student, Teacher)
R2(Teacher, Subject)
Now table is in 3NF, as well as in BCNF.
This show that the relation Every relation which is in BCNF is in 3NF but the converse
is not true.
Example 4.18.7 Consider relational schema R(A,B,C) with FD’s AB->C and C->A. Show that
schema R is in 3NF but not in BCNF. Determine minimal keys of R.
rd
Solution : A table is said to be in 3 normal from when,
nd
i) It is in 2 normal form.
ii) It doesn’t have transitive dependency or in other words L.H.S must be a candidate
key or R.H.S is prime attribute.
st
For 1 Condition :
nd
Step 1 : For 2 Normal form condition :
st
Step A : It is in 1 normal form
Step B : Table not contain partial dependency i.e. all the non-prime attributes should be
fully functionally dependent on candidate key.
Given relation R (A, B, C)
FD : AB C, C A
We will first find out the candidate key from the given FD.
+
(AB) = {ABC} = R,
+
(CB) = {ABC} = R,
+
(C) = {CA} R
+ +
They we obtain (AB) and (CB) candidate key.
Hence, prime attributes = {ABC}
None prime attributes = {C}
Hence, For AB C
AB is candidate key and its present at R.H.S for C A.
C is also candidate key and its present at R.H.S. There is no partial dependency. Hence
it is in 2nd normal form.
+ +
Step 2 : Candidate key = (AB) and (CB)
Prime attributes (ABC)
Non prime attribute ( ) Null
For given DF’s AB C, C A
Solution :
1. 3NF stands for Third Normal Form. BCNF stands for Boyce Codd Normal
Form.
2. The table is in 3NF if it is in 2NF and for The table is in BCNF if it is in 3rd normal
each functional dependency X->Y at least form and for each relation X->Y X
following condition hold: should be super key.
(i) X is a superkey,
3. 3NF can be obtained without sacrificing all Dependencies may not be preserved in
dependencies. BCNF.
5. 3NF can be achieved without loosing any For obtaining BCNF we may loose some
information from the old table. information from old table.
(i) The key for this relation is (Book_title, Authorname). This relation is in 1NF and not
in 2NF as no attributes are Fully Functionally Dependent on the key.
Step 2 : Now we will decompose it further to bring the table in 3rd Normal form
R1(book_title, authorname)
R2(book_title, publisher,book_type,listprice)
R21(book_title, publisher,book_type)
R22(book_type, listprice)
R3(authorname,authoraffiliation)
Review Question