0% found this document useful (0 votes)
14 views

Functional Dependency

DBMS NOTES

Uploaded by

ADARSH YADAV
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Functional Dependency

DBMS NOTES

Uploaded by

ADARSH YADAV
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Unit 3: Normalization in Design of

Databases

Functional Dependency, Different anomalies in


designing a Database, loss less join decompositions,
Normalization : first second and third normal forms,
BoyceCodd normal form, dependency preservation,
multi-valued dependencies , fourth normal forms,
Inclusion dependencies.
Trivial Functional Dependency

• A trivial functional dependency occurs when Q is


a subset of P in −
P ->Q
• For example: Let us now consider the same
<Section> table with two separate attributes to
comprehend the trivial dependency’s concept.
Here is a trivial functional dependency because
SecId is a subset of SecId and SecName.
• { Sec_Id, Sec_Name } -> Sec Id
Non –Trivial Functional Dependency

• A non-trivial functional dependency occurs


when Q is not a subset of P in −
P -> Q
• For example: Sec_Id -> Sec_Name
The FD given above is a functional
dependency that is of a non-trivial type since
SecName is not a subset of SecId.
Multivalued Dependency in DBMS

Multivalued dependency occurs in the


situation where there are multiple
independent multivalued attributes in a
single table.
In this example, maf_year and color are
independent of each other but dependent on
car_model, these two columns are said to be
multivalue dependent on car_model.
This dependence can be represented like this:
• car_model -> maf_year
• car_model-> colour
Transitive Dependency in DBMS

• Whenever some indirect relationship happens to cause


functional dependency (FC), it is known as Transitive
Dependency. Thus, if A -> B and B -> C are true, then A -> C
happens to be a transitive dependency.
• The given functional dependency can only be transitive
when it is formed indirectly by two FDs. For example,
P -> R happens to be a transitive dependency when the
following functional dependencies hold true:
• P -> Q
• Q -> R
• P -> R
Anomalies in designing a Database
Redundancy in DBMS is the problem that arises when the
database is not normalized. It is the concept of storing
multiple copies of the same data in different parts of the
database.
• Insertion Anomaly:
An insertion anomaly occurs when specific details cannot be
inserted into the database without the other details.
• Example: Without knowing the department details, we
cannot insert the student details in the above table. The
student details (student_id, student_name, and student_age)
depends on the department details (dept_id, dept_name,
and dept_head).
Deletion Anomaly

Deletion anomaly occurs when deleting


specific details loses some
unrelated information from the database.
Example: If we delete the student
with student_id 3 from the
above student table, we also lose the
department details with dept_id 101. Deleting
student details result in
losing unrelated department details.
Updation Anomaly

Updation anomaly occurs when there is data


inconsistency resulting from a partial data
update.
Example: We wanted to update
the dept_head to Prakash for dept_id 101; we
need to update it in all places. If the update
didn't occur in all the places (partial update), it
may result in data inconsistency.
Closure of an Attribute Set

• The set of all those attributes which can be functionally determined from an
attribute set is called as a closure of that attribute set.
• Closure of attribute set {X} is denoted as {X}+.
Steps to Find Closure of an Attribute Set-

Step-01: Add the attributes contained in the attribute set for which closure is being
calculated to the result set.
Step-02: Recursively add the attributes to the result set which can be functionally
determined from the attributes already contained in the result set.
Algorithm:
• Determine X+, the closure of X under functional dependency set F
• X Closure : = will contain X itself;
• Repeat the process as:
• old X Closure : = X Closure;
• for each functional dependency X → Y in FD set do
• Repeat until ( X Closure = old X Closure);
Find closure of QR and PR
• Given relational schema R( P Q R S T U V) having
following attribute P Q R S T U and V, also there is a set of
functional dependency denoted by FD = { P->Q, QR->ST,
PTV->V }.
• Determine Closure of (QR)+ and (PR)+
a) QR+ = QR (as the closure of an attribute or set of
attributes contain same).
Now as per algorithm look into a set of FD that complete
the left side of any FD contains either Q, R, or QR since in
FD QR→ST has complete QR.
Hence QR+ = QRST
• b) PR + = PR (as the closure of an attribute or set of attributes
contain same)
• Now as per algorithm look into a set of FD, and check that complete
left side of any FD contains either P, R, or PR. Since in FD P→Q, P is a
subset of PR, Hence PR+ = PRQ
• Again, trace the remaining two FD that any left part of FD contains
any P, R, Q, Since, in FD QR → ST has its complete left part QR in PQR
• Hence PR+ = PRQST
• Again trace the remaining one FD { PTV->V } that its complete left
belongs to PRQST. Since complete PTV is not in PRQST, hence we
ignore it.
• Therefore PR+ = PRQST ( Answer)
Armstrong’s Axioms in Functional Dependency in DBMS

Armstrong's Axioms has two different set of rules,


1. Axioms or primary rules
1.Axiom of Reflexivity
2.Axiom of Augmentation
3.Axiom of Transitivity
2. Additional rules or Secondary rules
1.Union
2.Composition
3.Decomposition
4.Pseudo Transitivity
1. Axiom of Reflexivity:

If A is a set of attributes and B is a subset of A, then A holds B. { A


→B}

Example:
X = {a, b, c, d, e}
Y = {a, b, c}
2. Axiom of Augmentation:

If A hold B and C is a set of attributes, then AC holds BC. {AC →


BC}
i.e, if X→Y then XA→YA,
where A is set of attributes

Example:
For R(ABCD), if A → B then AC → BC
3. Axiom of Transitivity:

If A holds B and B holds C, then A holds C.


i.e, If {A → B} and {B → C}, then {A → C}

If A holds B {A → B} means that A functionally


determines B.

Example:
if (X→Y & Y→Z) then X→Z
Secondary Rules - Union

If X determines Y and X determines Z, then X must also determine Y


and Z.
i.e, If X → Y and X → Z then X → YZ

Proof:

1. X → Y (given)
2. X → Z (given)
3. X → XY (using Augmentation Rule on 1 by augmentation with X.
Where XX = X)
4. XY → YZ (using Augmentation Rule on 2 by augmentation with Y)
5. X → YZ (using Transitive Rule on 3 and 4)
2. Decomposition
If X determines Y and Z, then X determines Y and X determines Z
separately.
i.e, If X → YZ then X → Y and X → Z

Proof:

1. X → YZ (given)
2. YZ → Y (using Reflexivity Rule)
3. X → Y (using Transitive Rule on 1 and 2) ……….(i)
4. X → YZ (given)
5. YZ → Z (using Reflexivity Rule)
6. X → Z (using Transitive Rule on 4 and 5) ………..(ii)
3. Composition
If P holds Q (P → Q) and A holds B (A → B), then PA → QB.

Proof,
1. P → Q (Given)
2. A → B (Given)
3. PA → QA (Augmentation of 1 and A)
4. PA → Q (Decomposition of 3)
5. PA → PB (Augmentation of 2 and P)
6. PA → B (Decomposition of 5)
7. PA → QB (Union 4 and 6)
Find minimal cover/canonical cover in a set of given functional dependencies

• Minimal cover:
• Definition 1:
• A minimal cover of a set of FDs F is a minimal set
of functional dependencies Fmin that is equivalent
to F. There can be many such minimal covers for a
set of functional dependencies F.
• Definition 2:
• A set of FDs F is minimum if F has as few FDs as
any equivalent set of FDs.
Canonical Cover Of Functional Dependency:

• Canonical Cover Of Functional Dependency : Example


• Consider a relation R(A,B,C,D) having some attributes and below are
mentioned functional dependencies.
• FD1 : B -> A
• FD2 : AD -> C
• FD3 : C -> ABD
• Step-1 : Decompose the functional dependencies using Decomposition
rule(Armstrong’s Axiom) i.e. single attribute on right hand side.
• FD1 : B -> A
• FD2 : AD -> C
• FD3 : C -> A
• FD4 : C-> B
• FD5 : C -> D
• Step-2 : Remove extraneous attributes from LHS of functional
dependencies by calculating the closure of FD’s having two or more
attributes on LHS.
• Here, only one FD has two or more attributes of LHS i.e. AD -> C.
• {A}+ = {A}
• {D}+ = {D}
• In this case, attribute “A” can only determine “A” and “D” can only
determine “D”. Hence, no extraneous attributes are present and the
FD will remain the same and will not be removed.
• Step-3 : Remove FD’s having transitivity.
• FD1 : B-> A
• FD2 : C -> A
• FD3 : C-> B
• FD4 : AD -> C
• FD5 : C-> D
• Above FD1, FD2 and FD3 are forming transitive pair.
Hence, using Armstrong’s law of transitivity i.e. if X Y, Y X
then X Z should be removed. Therefore we will have the
following FD’s left :
• FD1 : B ->A
• FD2 : C-> B
• FD3 : AD -> C
• FD4 : C -> D
• Also, FD2 & FD4 can be clubbed together now. Hence, the
canonical cover of the relation R(A,B,C,D) will be:
• Mc {R(ABCD)} = {B-> A , C ->BD, AD -> C}
Equivalence of sets of functional
dependencies
• A set of functional dependencies (FD) F is said
to cover another set of functional
dependencies E if every FD in E is also in F
closure; that is, if every dependency in E can
be inferred from F.
Example
• Consider the relational database :
• where the primary keys are underlined. Give an expression in the relational algebra to express
each of the following queries:
• a. Find the names of all employees who work for First Bank Corporation.
• b. Find the names and cities of residence of all employees who work for First Bank Corporation.
• c. Find the names, street address, and cities of residence of all employees who work for First Bank
Corporation and earn more than $10,000 per annum.
• d. Find the names of all employees in this database who live in the same city as the company for
which they work.
• e. Find the names of all employees who live in the same city and on the same street as do their
managers.
• f. Find the names of all employees in this database who do not work for First Bank Corporation.
• g. Find the names of all employees who earn more than every employee of Small Bank
Corporation.
• h. Assume the companies may be located in several cities. Find all companies located in every city
in which Small Bank Corporation is located

You might also like