Upload
sandipan-saha
View
220
Download
0
Embed Size (px)
DESCRIPTION
function
Citation preview
Functional Functional DependencyDependency
Rajhdeep JandirRajhdeep Jandir
DefinitionDefinition
A functional dependency is defined as a A functional dependency is defined as a constraint between two sets of constraint between two sets of attributes in a relation from a attributes in a relation from a database.database.
Given a relation Given a relation RR, a set of , a set of attributesattributes XX in in RR is said to is said to functionally determinefunctionally determine another attribute another attribute YY, also in , also in RR, (written , (written XX → → YY) ) if and only ifif and only if each each XX value is value is associated with at most one associated with at most one YY value. value.
In other words….In other words….
XX is the is the determinant setdeterminant set and and YY is the is the dependent attributedependent attribute. Thus, given a . Thus, given a tupletuple and the values of the attributes and the values of the attributes in in XX, one can determine the , one can determine the corresponding value of the corresponding value of the YY attribute. attribute.
ExampleExample
Employee Employee
SSNSSN NameName JobTypeJobType DeptNameDeptName
557-78-557-78-65876587
Lance Lance SmithSmith
AccountanAccountantt
SalarySalary
214-45-214-45-23982398
Lance Lance SmithSmith
EngineerEngineer ProductProduct
Note: Name is functionally dependent on SSN because an employee’s name can be uniquely determined from their SSN. Name does not determine SSN, because more than one employee can have the same name..
KeysKeys
Whereas a key is a set of attributes that Whereas a key is a set of attributes that uniquely identifies an entire tuple, a uniquely identifies an entire tuple, a functional dependency allows us to functional dependency allows us to express constraints that uniquely express constraints that uniquely identify the values of certain attributes. identify the values of certain attributes.
However, a candidate key is always a However, a candidate key is always a determinant, but a determinant doesn’t determinant, but a determinant doesn’t need to be a key. need to be a key.
ClosureClosure
Let a relation Let a relation RR have some functional have some functional dependencies dependencies FF specified. The specified. The closure of Fclosure of F (usually written as (usually written as F+F+) is the set of all ) is the set of all functional dependencies that may be logically functional dependencies that may be logically derived from derived from FF. Often . Often FF is the set of most is the set of most obvious and important functional dependencies obvious and important functional dependencies and and F+F+, the closure, is the set of all the , the closure, is the set of all the functional dependencies including functional dependencies including FF and those and those that can be deduced from that can be deduced from FF. The closure is . The closure is important and may, for example, be needed in important and may, for example, be needed in finding one or more candidate keys of the finding one or more candidate keys of the relation. relation.
ExampleExample StudentStudent
SNoSNo SNaSNameme
CNoCNo CNamCNamee
AddrAddr Instr.Instr. OfficOfficee
54255425 SusaSusan n
RossRoss
102102 Calc ICalc I ……San San Jose, Jose, CACA
P. P. SmitSmit
hh
B42 B42
RooRoom m
112112
78457845 DaveDave
TurcTurcoo
541541 Bio Bio 1010
......SaSan n
DiegDiego, o, CACA
L. L. TalipTalip
B24 B24 RooRoom m
210 210
SNo -> SName CNo -> CName Instr -> OfficeSNo -> Addr CNo -> Instr
AxiomsAxioms
Before we can determine the closure Before we can determine the closure of the relation, Student, we need a of the relation, Student, we need a set of rules. set of rules.
Developed by Armstrong in 1974, Developed by Armstrong in 1974, there are six rules (axioms) that all there are six rules (axioms) that all possible functional dependencies possible functional dependencies may be derived from them. may be derived from them.
Axioms Cont.Axioms Cont.
1. Reflexivity Rule1. Reflexivity Rule --- If --- If XX is a set of is a set of attributes and attributes and YY is a subset of is a subset of XX, , then then X X Y Y holds. holds. each subset of each subset of XX is functionally dependent on is functionally dependent on XX. .
2.2. Augmentation RuleAugmentation Rule --- If --- If X X Y Y holds holds and and WW is a set of attributes, then is a set of attributes, then WX WX WY WY holds. holds.
3. Transitivity Rule3. Transitivity Rule --- If --- If X X Y Y and and Y Y ZZ holds, then holds, then X X Z Z holds. holds.
Derived Theorems from Derived Theorems from AxiomsAxioms
4. 4. Union RuleUnion Rule --- If --- If X X Y Y and and X X Z Z holds, then holds, then X X YZ YZ holds. holds.
5. 5. Decomposition RuleDecomposition Rule --- If --- If X X YZ YZ holds, then so do holds, then so do X X Y Y and and X X Z Z. .
6. 6. Pseudotransitivity RulePseudotransitivity Rule --- If --- If X X Y Y and and WY WY Z Z hold then so does hold then so does WX WX ZZ. .
Back to the ExampleBack to the Example
SNoSNo SNaSNameme
CNoCNo CNaCNameme
AddrAddr Instr.Instr. OfficOfficee
Based on the rules provided, the following dependencies can be derived.
(SNo, CNo) SNo (Rule 1) -- subset (SNo, CNo) CNo (Rule 1) (SNo, CNo) (SName, CName) (Rule 2) -- augmentationCNo office (Rule 3) -- transitivitySNo (SName, address) (Union Rule) etc.
Too Many FDsToo Many FDs
Using the first rule alone, from our example Using the first rule alone, from our example we have 2^7 = 128 subsets. This will we have 2^7 = 128 subsets. This will further lead to many more functional further lead to many more functional dependencies. This defeats the purpose of dependencies. This defeats the purpose of normalizing relations. normalizing relations.
So what now?So what now?One way is to deal with one attribute or a One way is to deal with one attribute or a
set of attributes at a time and find its set of attributes at a time and find its closure (i.e. all functional dependencies closure (i.e. all functional dependencies relating to them). The aim of this exercise relating to them). The aim of this exercise is to find what attributes depend on a is to find what attributes depend on a given set of attributes and therefore ought given set of attributes and therefore ought to be together. to be together.
The approachThe approach
Step 1 Let Step 1 Let X^c <- XX^c <- X
Step 2 Let the next dependency be Step 2 Let the next dependency be A -A -> B> B. If . If AA is is
in in X^cX^c and and BB is not, is not, X^c <- X^c <- X^c + BX^c + B. .
Step 3 Continue step 2 until no new Step 3 Continue step 2 until no new attributes can attributes can
be added to be added to X^cX^c. .
Back To Our ExampleBack To Our ExampleConsider the following relation: student(SNo, SName, CNo, Consider the following relation: student(SNo, SName, CNo,
CName). CName). We wish to determine the closure of (SNo, CNo). We have the We wish to determine the closure of (SNo, CNo). We have the
following functional dependencies. following functional dependencies. SNo -> SNameSNo -> SNameCNo -> CNameCNo -> CName Step 1Step 1 --- --- X^c <- XX^c <- X, that is, , that is, X^c <- (SNo, CNo)X^c <- (SNo, CNo)
Step 2Step 2 --- Consider --- Consider SNo -> SNameSNo -> SName, since , since SNoSNo is in is in X^cX^c and and SNameSName is not, we have: is not, we have: X^c <- (SNo, CNo) + SNameX^c <- (SNo, CNo) + SName Step 3Step 3 --- Consider --- Consider CNo -> CNameCNo -> CName, since , since CNoCNo is in is in X^cX^c and and CNameCName is not, we have: is not, we have: X^c <- (SNo, CNo, SName) + X^c <- (SNo, CNo, SName) + CNameCName Step 4Step 4 --- Again, consider --- Again, consider SNo -> SNameSNo -> SName but this does not but this does not change change X^cX^c..Step 5Step 5 --- Again, consider --- Again, consider CNo -> CNameCNo -> CName but this does not but this does not change change X^cX^c. .
Therefore Therefore X+ = X^c = (SNo, CNo, SName, CName)X+ = X^c = (SNo, CNo, SName, CName). . This shows that all the attributes in the relation This shows that all the attributes in the relation student (SNo, student (SNo,
CNo, SName, CName)CNo, SName, CName) are dependent on are dependent on (SNo, CNo)(SNo, CNo) and and therefore therefore (SNo, CNo)(SNo, CNo) is a candidate key of the present is a candidate key of the present relation. In this case, it is the only candidate key. relation. In this case, it is the only candidate key.
Normal FormNormal Form
Initially Codd (1972) presented three Initially Codd (1972) presented three normal forms (1NF, 2NF and 3NF) all based normal forms (1NF, 2NF and 3NF) all based on functional dependencies among the on functional dependencies among the attributes of a relation. Later Boyce and attributes of a relation. Later Boyce and Codd proposed another normal form called Codd proposed another normal form called the Boyce-Codd normal form (BCNF). The the Boyce-Codd normal form (BCNF). The fourth and fifth normal forms are based on fourth and fifth normal forms are based on multi-value and join dependencies and were multi-value and join dependencies and were proposed later. proposed later.
The primary objective of normalization is to The primary objective of normalization is to avoid anomalies.avoid anomalies.