Sei sulla pagina 1di 12

Functional Dependency

Definition: A set of attributes X functionally


determines a set of attributes Y if the value of X
determines a unique value for Y.
This is similar to functions in mathematics. In
mathematics, a function f is said to be valid function
when for every value of x ,f(x) return single value of
y. For example, function y = x2 returns single value
of y for every value of x (at x=0 y=0,at x=1 y=1,at
x=2 y=4). Now consider the function, y=x this
function returns 2 values of by for every value of
x(for x=4 it returns y = -2 and y = +2). So it is not a
valid function. For a valid function we can say x
functionally determine y.

Ques. Consider Relation R(A,B,C) and


sample data in R

a1
a1
a2
a2

b1
b2
b3
b4

c1
c1
c2
c2

Which of the following dependencies holds


in R?
1. AA-->B
2. B-->A
3. B-->C
4. A-->C

Some rules for Functional dependencies:


Reflexivity: XX always holds. It means a attribute or
group of attribute always functionally determines
itself.
Transitivity: if XY and YZ then XZ
Pseudo-transitivity: if XY and YZW then XZW
Additivity: if XY and XZ then XYZ
Projectivity: if XYZ then XY and XZ
Augmentation: if XY then XZY
Where X,Y and Z are single attributes or group of
attributes of a relation.
Note: if ABC then you cant divide AB C into
AC and BC.

Closure of a attribute(*):
closure of attributes contains all attributes
those are directly or indirectly driven by this
attribute(using above rules).
Example: for a relation R(A,B,C,D), functional
dependencies are: AB , BC , BCD.
Closure of A: By 1st rule a attribute derives
itself so its closure contain A(i.e {A}*={A}). Now
from AB, B can be directly derive from B. if
AB and BC then AC(2nd rule), C can be
derived from A . similarly if AB and AC then
ABC(4th rule) and if ABC and BCD then
AD, so D can be derived from A.
A* = {A,B,C,D}
Simlarly, B*={B,C,D} , C*={C} , D*={D}

If closure of a attribute of attributes contains all attributes of


relation then attribute is candidate key of relation. In above
example A is candidate key of R.
Note: How to find closure of group of attributes: suppose we
want to find closure of BC in above example then closure of BC
contains attribute directly or indirectly driven by B,C and BC.
{BC}*={B,C,D}
Q. consider following functional dependencies for relation
R(A,B,C,D,E,F,G,H,I,J,K)
ABC , ADE, BF , FGH , D IJ
Find closure of AB
Ans. {AB}* ={A,B,C,D,E,F,G,H,I,J}
Note: in above example AB is not candidate key of R since K is not in
closure of AB. K is also not in any functional dependency. Attributes
those are not in any functional dependency must be part of
candidate key, so candidate key of R is ABK.

Normalization
Normalization: To remove data
redundancy and anomalies we Normalize
table by decomposing into multiple tables.
Following normal forms are defined for
Normalization:
1st Normal Form:
a relation is said to be in 1st normal form if its
data is represented in tabular form or atomic
and there should not be duplicated row(whole
row should not be duplicated, at least value in
one same field of two rows must be different ).

2nd Normal Form(2NF) : To understand 2NF first


look at these terms:
Consider
relation
Student(Rollno,
Name,
CourceNo,CourceName, Deptid, DeptName)
Prime attribute: Attributes those are parts of
candidate key/primary key but not a candidate key.
For example, if {rollno , courseno , deptid} is
candidate key of student relation then rollno ,
courseno , {rollno, courseno}, {rollno,deptid} and
{courseno,deptid} are the prime attributes. In
other words, prime attributes are proper subset of
candidate keys.
Determinant: in functional dependency X Y , X
is determinant(attributes at the tail(left side) of
arrow)

Partial dependency: a functional dependency is


said to be partial when determinant is prime
attribute and right side of arrow have non-prime
attribute.
Consider
following
functional
dependencies for student relation defined above
and {rollno , courseno , deptid} as candidate key .
Rollno name
Prime)
Rollno,courseno,deptidname
partial(nonprimenon-Prime)
Rollnocourseno
partial(primePrime)
Name,courseno rollno
primePrime)

partial (primenonnot
not
not partial(non-

A relation is said to be in 2NF if and only if it is in


1NF and every non-key attribute is fully dependent
on the primary key. or in other words, A relation is
said to be in 2NF if and only if it is in 1NF and there
exist no partial dependency.

3rd Normal Form(3NF) : A relation R is in third


normal form (3NF) if and only if it is in 2NF and
every non-key(non-prime) attribute is nontransitively dependent on the primary key.
A functional dependency XY not violates 3NF
conditions if either X is candidate key or Y is prime
attribute , where X and Y attributes or group of
attributes. If any of the functional dependencies
violates 3NF conditions then relation is not in 3NF.
An attribute C is transitively dependent on
attribute A if there exists an attribute B such that:
AB and BC. Note that 3NF is concerned with
transitive dependencies which do not involve
candidate keys.

If A 3NF relation have more than one candidate key


then it can have transitive dependencies of the form:
primary_keyother_candidate_key any_nonkey_column.
A relation R having just one candidate key is in third
normal form (3NF) if and only if the non-key attributes
of R (if any) are:
1) mutually independent(attributes, those are not
present in any functional dependency, are mutually
independent) , and
2) fully dependent on the primary key of R.
A non-key attribute is any column which is not part of
the primary key. Two or more attributes are mutually
independent if none of the attributes is functionally
dependent on any of the others.
A relation R having just one candidate key is in third
normal form (3NF) if and only if no non-key(non-prime)
column (or group of columns) determines another non-

Thank You

Potrebbero piacerti anche