DBMS Module II
DBMS Module II
1. Explain about first normal form and second normal form with suitable example.
First Normal Form (1NF)
JDr.I.Jasmine 1
VIT Bhopal University
Module II
Example:
Consider the DEPARTMENT relation schema
o Primary key is Dnumber
o Each department can have a number of locations.
o The relation is not in 1NF because Dlocations is not an atomic attribute
▪ The domain of Dlocations contains atomic values, but some tuples
can have a set of these values. In this case, Dlocations is not
functionally dependent on the primary key Dnumber.
▪ The domain of Dlocations contains sets of values and hence is
nonatomic. In this case, Dnumber → Dlocations because each setis
considered a single member of the attribute domain.
There are three main techniques to achieve first normal form for such a relation:
(i) Remove the attribute Dlocations that violates 1NF and place it in a separate
relation DEPT_LOCATIONS along with the primary key Dnumber of
DEPARTMENT. The primary key of this relation is the combination
{Dnumber, Dlocation}, This decomposes the non-1NF relation into two 1NF
relations.
(i) Expand the key so that there will be a separate tuple in the original DEPARTMENT
relation for each location of a DEPARTMENT In this case, the primary key
becomes the combination {Dnumber, Dlocation}. This solution has the
disadvantage of introducing redundancy in the relation
(ii) If a maximum number of values is known for the attribute—for example, if it
is known that at most three locations can exist for a department—replace the
Dlocations attribute by three atomic attributes: Dlocation1, Dlocation2, and
Dlocation3. This solution has the disadvantage of introducing NULL values if most
departments have fewer than three locations
First normal form also disallows multivalued attributes that are themselves composite.
These are called nested relations because each tuple can have a relation within it.
Example
JDr.I.Jasmine 2
VIT Bhopal University
Module II
JDr.I.Jasmine 3
VIT Bhopal University
Module II
2. Explain different types of Normal forms based on the primary keys and discuss the
normal forms related to functional dependency with an example for each.
Refer Qno 1 and Qno 3
3. Discuss in detail about Third Normal Form and BCNF with an example.
Third Normal Form (3NF)
Third normal form (3NF) is based on the concept of transitive dependency.
A functional dependency X → Y in a relation schema R is a transitive dependency if
there exists a set of attributes Z in R that is neither a candidate key nor a subset of any
key of R and both X → Z and Z → Y hold
Definition. According to Codd’s original definition, a relation schema R is in 3NF
if it satisfies 2NF and no nonprime attribute of R is transitively dependenton the
primary key
Example:
The dependency Ssn → Dmgr_ssn is transitive through Dnumber in EMP_DEPT
because both the dependencies
o Ssn → Dnumber
o Dnumber → Dmgr_ssn hold
o Dnumber is neither a key itself nor a subset of the key of EMP_DEPT
EMP_DEPT is not in 3NF because of the transitive dependency of Dmgr_ssn (and
also Dname) on Ssn via Dnumber
Normalize EMP_DEPT by decomposing it into the two 3NF relation schemas ED1
and ED2 as shown below
JDr.I.Jasmine 4
VIT Bhopal University
Module II
ED1 and ED2 represent independent entity facts about employees and departments.
A NATURAL JOIN operation on ED1 and ED2 will recover the original relation
EMP_DEPT without generating spurious tuples.
JDr.I.Jasmine 5
VIT Bhopal University
Module II
This relation schema can be decomposed into one of the three following possible pairs
4. Explain multi valued dependencies and fourth normal form with suitable example.
Multivalued dependencies are a consequence of first normal form (1NF), which
disallows an attribute in a tuple to have a set of values, and the accompanying
process of converting an unnormalized relation into 1NF.
If we have two or more multivalued independent attributes in the same relation
schema, we have to repeat every value of one of the attributes with every value of the
other attribute to keep the relation state consistent and to maintain the independence
among the attributes involved. This constraint is specified by a multivalued
dependency.
A multivalued dependency (MVD) X —>> Y specified on relation schema R, where
X and Y are both subsets of R, specifies the following constraint on any relation state
r of R: If two tuples t1 and t2 exist in r such that t1[X] = t2[X], then two tuples t3 and t4
should also exist in r with the following properties, where we use Z todenote (R – (X
𝖴 Y)):
▪ t3[X] = t4[X] = t1[X] = t2[X].
▪ t3[Y] = t1[Y] and t4[Y] = t2[Y].
▪ t3[Z] = t2[Z] and t4[Z] = t1[Z].
Whenever X —>> Y holds, we say that X multidetermines Y
An MVD X —>> Y in R is called a trivial MVD
o if (a) Y is a subset of X, or
o (b) X 𝖴 Y = R.
Example:
A tuple in this EMP relation represents the fact that an employee whose name is
Ename works on the project whose name is Pname and has a dependent whose name
is Dname.
An employee may work on several projects and may have several dependents, and the
employee’s projects and dependents are independent of one another.
To keep the relation state consistent, and to avoid any spurious relationship between
the two independent attributes, we must have a separate tuple to represent every
combination of an employee’s dependent and an employee’s project. This constraint
is specified as a multivalued dependency on the EMP relation
JDr.I.Jasmine 6
VIT Bhopal University
Module II
5. What are the pitfalls in relational database design? With a suitable example,
explain the role of functional dependency in the process of normalization
Pitfalls in relational database design
Redundant Information in Tuples
Inability to represent certain information.
Problems with update anomalies
o Insertion anomalies
o Deletion anomalies
o Modification anomalies
Waste of storage space due to NULLs and the difficulty of performing selections,
aggregation operations, and joins due to NULL values
JDr.I.Jasmine 7
VIT Bhopal University
Module II
Functional Dependency
A functional dependency is a constraint between two sets of attributes from the
database.
A functional dependency, denoted by X → Y, between two sets of attributes X
and Y that are subsets of R specifies a constraint on the possible tuples that can
form a relation state r of R. The constraint is that, for any two tuples t1 and t2 in r
that have t1[X] = t2[X], they must also have t1[Y] = t2[Y].
The values of the Y component of a tuple depend on, or are determined by, the
values of the X component; alternatively, the values of the X component of a
tuple uniquely (or functionally) determine the values of the Y component.
Closure of F
The set of all dependencies that include F as well as all dependencies that can be
inferred from F is called the closure of F
It is denoted by F+
For example
A set of inference rules can be used to infer new dependencies from a given set of
dependencies.
Inference Rules
JDr.I.Jasmine 8
VIT Bhopal University
Module II
Example:
Let the given set of FDs be E : {B → A, D → A, AB → D}. We have to find the minimal
cover of E.
All above dependencies are in canonical form (that is, they have only one
attribute on the right-hand side) step 1 completed
In step 2 we need to determine if AB → D has any redundant attribute on the left-
hand side; that is, can it be replaced by B → D or A → D?
Since B → A, by augmenting with B on both sides (IR2), we have BB → AB, or B →
AB (i). However, AB → D as given (ii).
Hence by the transitive rule (IR3), we get from (i) and (ii), B → D. Thus AB → D
may be replaced by B → D.
JDr.I.Jasmine 9
VIT Bhopal University
Module II
Closure of {ABD}+
{ABD}+ = {ABD}
= {ABDC} by {A, B} → {C}
= {ABDCEF} by {B, D} → {E, F}
= {ABDCEFGH} by {A, D} → {G, H}
= {ABDCEFGHI} by {A} → {I}
= {ABCDEFGHIJ} by {H} → {J}
+
The Closure {ABD} contains all the attributes of the R. So ABD is a key.
JDr.I.Jasmine 10
VIT Bhopal University
Module II
Solution
a) Three candidate keys are {AB}, {BC}, and {BD}
{AB}+ = {AB}
= {ABC} by AB → C
= {ABCD} by C → D
{BC}+ = {BC}
= {BCD} by C → D
= {ABCD} by D → A
{BD}+ = {BD}
= {ABD} by D → A
= {ABCD} by AB → C
JDr.I.Jasmine 11
VIT Bhopal University
Module II
JDr.I.Jasmine 12
VIT Bhopal University
Module II
The performance is improved since the commands act on a set of records rather than
one record at a time.
Rule 8: Physical Data Independence
The execution of ad hoc requests and application programs is not affected by changes
in the physical data access and storage methods.
Rule 9: Logical Data Independence
Logical changes in tables and views such as adding / deleting columns or changing field
lengths need not necessary modifications in the programs or in the format of ad hoc
requests.
Rule 10: Integrity Independence
Integrity constraints specific to a particular relational database must be definable in the
relational data sublanguage and storable in the catalog, not in the application programs.
Rule 11: Distribution Independence
The data manipulation sublanguage of a relational DBMS must enable application
programs and terminal activities to remain logically unimpaired whether and whenever
data are physically centralized or distributed.
Rule 12: Non subversion Rule
If a relational system has or supports a low-level (single- record-at a-time) language,
that low-level language cannot be used to subvert or bypass the integrity rules or
constraints expressed in the higher-level (multiple- records-at-a-time) relational
language.
4. Suppose that we have the following four tuples in a relation S with three attributes
ABC (listed in order): (1,2,3),(4,2,3), (5,3,3),(5,3,4). Which of the following (->) and
multivalued (->->) dependencies can you infer does hold over relation S?
i. A->B
ii. A->->B
iii. BC->A
iv. BC->->A
v. B->C
vi. B->->C
Solution
A B C
1 2 3
4 2 3
5 3 3
5 3 4
1. A->B
With the available tuples, we cannot infer the dependency to hold
2. A->->B
1->->2
5->->3
Insufficient tuples to infer
JDr.I.Jasmine 13
VIT Bhopal University
Module II
3. BC->A
Does not hold
For the tuples (1,2,3) and (4,2,3) the BC-values are the same but A values differ
4. BC->->A
Holds
For the same BC-values A values differ
5. B->C
Does not hold
For the tuples (5,3,3) and (5,3,4) for the same value of B, C value differ
JDr.I.Jasmine 14
VIT Bhopal University