Successfully reported this slideshow.
Upcoming SlideShare
×

# Functional dependency

22,049 views

Published on

Published in: Technology, Health & Medicine
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### Functional dependency

1. 1. DefinitionA functional dependency is defined as aconstraint between two sets of attributesin a relation from a database.Given a relation R, a set of attributes X in Ris said to functionally determine anotherattribute Y, also in R, (written X → Y) ifand only if each X value is associatedwith at most one Y value.
2. 2. In other words….X is the determinant set and Y is thedependent attribute. Thus, given atuple and the values of the attributes inX, one can determine thecorresponding value of the Y attribute.
3. 3. ExampleEmployeeSSN Name JobType DeptName557-78-6587 Lance Smith Accountant Salary214-45-2398 Lance Smith Engineer ProductNote: Name is functionally dependent on SSN because an employee’s namecan be uniquely determined from their SSN. Name does not determine SSN,because more than one employee can have the same name..
4. 4. KeysWhereas a key is a set of attributes that uniquelyidentifies an entire tuple, a functionaldependency allows us to express constraintsthat uniquely identify the values of certainattributes.However, a candidate key is always adeterminant, but a determinant doesn’t needto be a key.
5. 5. ClosureLet a relation R have some functional dependencies Fspecified. The closure of F (usually written as F+) isthe set of all functional dependencies that may belogically derived from F. Often F is the set of mostobvious and important functional dependencies andF+, the closure, is the set of all the functionaldependencies including F and those that can bededuced from F. The closure is important and may,for example, be needed in finding one or morecandidate keys of the relation.
6. 6. ExampleStudentSNo SName CNo CName Addr Instr. Office5425 SusanRoss102 Calc I …SanJose,CAP. Smith B42Room1127845 DaveTurco541 Bio 10 ...SanDiego,CAL. Talip B24Room210SNo -> SName CNo -> CName Instr -> OfficeSNo -> Addr CNo -> Instr
7. 7. AxiomsBefore we can determine the closure ofthe relation, Student, we need a set ofrules.Developed by Armstrong in 1974, thereare six rules (axioms) that all possiblefunctional dependencies may bederived from them.
8. 8. Axioms Cont.1. Reflexivity Rule --- If X is a set of attributes andY is a subset of X, then X  Y holds.each subset of X is functionally dependent on X.2. Augmentation Rule --- If X  Y holds and W isa set of attributes, then WX  WY holds.3. Transitivity Rule --- If X  Y and Y  Z holds,then X  Z holds.
9. 9. Derived Theorems fromAxioms4. Union Rule --- If X  Y and X  Zholds, then X  YZ holds.5. Decomposition Rule --- If X  YZholds, then so do X  Y and X  Z.6. Pseudotransitivity Rule --- If X  Yand WY  Z hold then so does WX Z.
10. 10. Back to the ExampleSNo SName CNo CName Addr Instr. OfficeBased on the rules provided, the following dependencies can bederived.(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.
11. 11. Too Many FDsUsing the first rule alone, from our example wehave 2^7 = 128 subsets. This will further leadto many more functional dependencies. Thisdefeats the purpose of normalizing relations.So what now?One way is to deal with one attribute or a set ofattributes at a time and find its closure (i.e. allfunctional dependencies relating to them). Theaim of this exercise is to find what attributesdepend on a given set of attributes andtherefore ought to be together.
12. 12. The approachStep 1 Let X^c <- XStep 2 Let the next dependency be A -> B.If A isin X^c and B is not, X^c <- X^c + B.Step 3 Continue step 2 until no newattributes canbe added to X^c.
13. 13. Back To Our ExampleConsider the following relation: student(SNo, SName, CNo,CName).We wish to determine the closure of (SNo, CNo). We have thefollowing functional dependencies.SNo -> SNameCNo -> CName Step 1 --- X^c <- X, that is, X^c <- (SNo, CNo)Step 2 --- Consider SNo -> SName, since SNo is in X^c and SName is not, wehave: X^c <- (SNo, CNo) + SNameStep 3 --- Consider CNo -> CName, since CNo is in X^c and CName is not, wehave: X^c <- (SNo, CNo, SName) + CNameStep 4 --- Again, consider SNo -> SName but this does not change X^c.Step 5 --- Again, consider CNo -> CName but this does not change X^c. Therefore X+ = X^c = (SNo, CNo, SName, CName). This shows that all the attributes in the relation student (SNo, CNo, SName,CName) are dependent on (SNo, CNo) and therefore (SNo, CNo) is a candidate keyof the present relation. In this case, it is the only candidate key.
14. 14. Normal Form Initially Codd (1972) presented three normalforms (1NF, 2NF and 3NF) all based onfunctional dependencies among the attributesof a relation. Later Boyce and Codd proposedanother normal form called the Boyce-Coddnormal form (BCNF). The fourth and fifthnormal forms are based on multi-value andjoin dependencies and were proposed later. The primary objective of normalization is toavoid anomalies.