0% found this document useful (0 votes)
25 views14 pages

DBMS Module II

All about dbms

Uploaded by

N M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views14 pages

DBMS Module II

All about dbms

Uploaded by

N M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Module II

CSE3001 - DATABASE MANAGEMENT SYSTEMS


MODULE II

1. Explain about first normal form and second normal form with suitable example.
First Normal Form (1NF)

Disallows composite attributes, multivalued attributes, and their combinations;


1NF disallows relations within relations or relations as attribute values within tuples
States that the domain of an attribute must include only atomic (simple, indivisible)
values and that the value of any attribute in a tuple must be a single value from the
domain of that attribute
Considered to be part of the definition of relation

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

Second Normal Form (1NF)


Uses the concepts of FDs, primary key
Definitions:
o Prime attribute - attribute that is member of the primary key K
o Full functional dependency - a FD X → Y where removal of any attribute A
from X means the FD does not hold any more
o Partial functional dependency - if some attribute A ε X can be removed from
X and the dependency X → Ystill holds
A relation schema R is in 2NF if every nonprime attribute A in R is
fully functionally dependent on the primary key of R.
Example
{SSN, PNUMBER} → HOURS is a full FD since neither SSN → HOURS
nor PNUMBER → HOURS hold
{SSN, PNUMBER} → ENAME is not a full FD (it is called a partial
dependency ) since SSN → ENAME also holds
If a relation schema is not in 2NF, it can be second normalized or 2NF normalized
into a number of 2NF relations in which nonprime attributes are associated only
with the part of the primary key on which they are fully functionally dependent
Normalizing EMP_PROJ into 2NF relations as shown below

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.

Boyce-Codd normal form (BCNF)


Stricter than 3NF. That is, every relation in BCNF is also in 3NF; however, a relation
in 3NF is not necessarily in BCNF
Definition A relation schema R is in BCNF if whenever a nontrivial functional
dependency X → A holds in R, then X is a superkey of R.
Most relation schemas that are in 3NF are also in BCNF. Only if X → A holds
in a relation schema R with X not being a superkey and A being a prime attribute will
R be in 3NF but not in BCNF.
A schematic relation with FDs; it is in 3NF, but not in BCNF.

Example which shows a relation TEACH with the following dependencies:


o FD1: {Student, Course} → Instructor
o FD2: Instructor → Course
o {Student, Course} is a candidate key for this relation
o This relation is in 3NF but not BCNF.

JDr.I.Jasmine 5
VIT Bhopal University
Module II

This relation schema can be decomposed into one of the three following possible pairs

All three decompositions lose the functional dependency FD1.


The desirable decomposition is {Instructor, Course} and {Instructor, Student}
because it will not generate spurious tuples after a join.
Each normal form is strictly stronger than the previous one:
o Every 2NF relation is in 1NF
o Every 3NF relation is in 2NF
o Every BCNF relation is in 3NF

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

A functional dependency X → Y is trivial if X ⊇ Y; otherwise, it is nontrivial.

JDr.I.Jasmine 8
VIT Bhopal University
Module II

Minimal Sets of Functional Dependencies


A minimal cover of a set of functional dependencies E is a set of functional
dependencies F that satisfies the property that every dependency in E is in the closure
F+ of F
A set of functional dependencies F to be minimal if it satisfies the following
conditions:

Finding a Minimal Cover F for a Set of Functional Dependencies E

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

We now have a set equivalent to original E, say E’: {B → A, D → A, B → D}. No


further reduction is possible in step 2 since all FDs have a single attribute on the left-
hand side.
In step 3 we look for a redundant FD in E’. By using the transitive rule on B → D and
D → A, we derive B → A. Hence B → A is redundant in E’ and can be eliminated.
Therefore, the minimal cover of E is {B → D, D → A}.

Finding a Key K for R Given a set F of Functional Dependencies

Numerical Type Question

1. Consider the relation R = {A, B, C, D, E, F, G, H, I, J} and the set of functional


dependencies F = {{A, B} → {C}, {B, D} → {E, F}, {A, D} → {G, H}, {A} → {I}, {H}
→ {J}}.
a) What are the keys of R
b) Decompose R into 2NF
c) Decompose that further into 3NF

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

2. Let R=(A, B, C, D) a relation and F ={AB --> C, C--> D, D --> A} a set of


dependencies for this relation.
a) Find the canditate keys in R.
b) Find the possible violations of R when {A,B} is defined as primary key.
c) If R is not in BCNF, give a decomposition of R in relations that will be in BCNF

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

b) BCNF violations for R


C--> D, D --> A
c)

JDr.I.Jasmine 11
VIT Bhopal University
Module II

3. Explain the codd‟s rules for relational database design.


CODD’s RULES
Dr. E. F. Codd the founder of the Relational Database systems.
Codd's twelve rules call for a language that can be used to define, manipulate, and
query the data in the database, expressed as a string of characters.
Rule 1: Information Rule
All information in the relational database including table name, column names is
represented by values in tables.
Improves the data speeds design and learning process.
Only one language is needed to access all data as description of the table and attribute
definitions. Hence the user productivity is improved.
Access to data can be restricted.
Rule 2: Guaranteed Access Rule
To guarantee the access rule, every piece of data in a relational database can be accessed
by using a combination of table name, primary key value that identifies the row and a
column name which identifies a cell.
No need of using physical pointers or add record to resort which improves the user
productivity.
It also provides data independence and it is possible to retrieve each individual piece of
data store in a relational database.
Rule 3: Systematic Treatment of Null Values
Null values (distinct from empty character string or a string of blank characters and
distinct from zero or any other number) are supported in the fully relational DBMS
for representing missing information in a systematic way, independent of data
type.
Rule 4: Dynamic Online Catalog Based on the Relational Model
The database description is represented at the logical level in the same way asordinary
data, so authorized users can apply the same relational language to its interrogation as
they apply to regular data.
Rule 5: Comprehensive Data Sublanguage Rule
A relational system may support several languages and various modes of terminal use.
However, there must be at least one language whose statements are expressible,per
some well-defined syntax, as character strings and whose ability to support all ofthe
following is comprehensible:
a. Data definition
b. View definition
c. Data manipulation (interactive and by program)
d. Integrity constraints
e. Authorization
f. Transaction boundaries (begin, commit, and rollback).
Rule 6: View Updating Rule
All views can be updated using the RDBMS and hence the data consistency is
ensured.
Rule 7: High-Level Insert, Update, and Delete
The RDBMS supports insertion, updating and deletion at a table level.

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

You might also like