This document discusses functional dependencies in relational database design. It defines functional dependencies as constraints where the value of one set of attributes determines the value of another set. Armstrong's rules are presented for inferring new functional dependencies from existing ones. Closure is defined as the set of all functional dependencies that can be logically derived from a set of given dependencies. Examples of functional dependencies in relations and relationships are provided.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
79 views
Functional Dependency: - Kma@ittelkom - Ac.id
This document discusses functional dependencies in relational database design. It defines functional dependencies as constraints where the value of one set of attributes determines the value of another set. Armstrong's rules are presented for inferring new functional dependencies from existing ones. Closure is defined as the set of all functional dependencies that can be logically derived from a set of given dependencies. Examples of functional dependencies in relations and relationships are provided.
CS2343 – RELATIONAL DATABASE DESIGN Basic Concepts • A constraint on the set of legal relations to express facts about the enterprise for modeling database. • Require that the value for a certain set of attributes determines • uniquely the value for another set of attributes. • A functional dependency is a generalization of the notion of a key. INFORMATICS DEPARTMENT – IT TELKOM CS2343 – RELATIONAL DATABASE DESIGN Concept (cont.) • Functional dependencies (FDs) are used to specify formal measures of the "goodness" of relational designs • FDs and keys are used to define normal forms for relations • FDs are constraints that are derived from the meaning and interrelationships of the data attributes
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Definition • A set of attributes X functionally determines a set of attributes Y if the value of X determines a unique value for Y • X Y holds if whenever two tuples have the same value for X, they must have the same value for Y If t1[X]=t2[X], then t1[Y]=t2[Y] in any relation instance r(R) • X Y in R specifies a constraint on all relation instances r(R) • FDs are derived from the real-world constraints on the attributes
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Examples of FD constraints • Social Security Number determines employee name SSN ENAME • Project Number determines project name and location PNUMBER {PNAME, PLOCATION} • Employee SSN and project number determines the hours per week that the employee works on the project {SSN, PNUMBER} HOURS
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Inference Rules for FDs • Given a set of FDs F, we can infer additional FDs that hold whenever the FDs in F hold • Armstrong's inference rules A1. (Reflexive) If Y subset-of X, then X Y A2. (Augmentation) If X Y, then XZ YZ (Notation: XZ stands for X U Z) A3. (Transitive) If X Y and Y Z, then X Z • A1, A2, A3 form a sound and complete set of inference rules
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Armstrong's Rules 1. Reflexivity Rule – If X is a set of attributes and Y 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 is a set of attributes, then WX -> WY holds – If Y is determined by X then a set of attributes W and Y together will be determined by W and X together 3. Transitivity Rule – If X -> Y and Y -> Z hold, then X -> Z holds – If X functionally determines Y and Y functionally determines Z then X functionally determines Z.
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Additional Useful Inference Rules 1. Decomposition – If X YZ, then X Y and X Z 2. Union – If X Y and X Z, then X YZ 3. Psuedotransitivity – If X Y and WY Z, then WX Z
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Closure (F+) • The set of all functional dependencies that may be logically derived from F • For example, the student relation has the following functional dependencies – sno -> sname cno -> cname sno -> address cno -> instructor instructor -> office
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Closure Algorithms 1. Let X^c <- X 2. Let the next dependency be A -> B. If A is in X^c and B is not, X^c <- X^c + B. 3. Continue step 2 until no new attributes can be added to X^c. • The result of the algorithm is X^c that is equal to X+.
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Closure Example (1) • Consider the following relation – student(sno, sname, cno, cname). • Determine the closure of (sno, cno). We have the following functional dependencies. – sno -> sname – cno -> cname
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Closure Example (2) 1. Step 1 --- X^c <- X, that is, X^c <- (sno, cno) 2. Step 2 --- Consider sno -> sname, since sno is in X^c and sname is not, we have X^c <- (sno, cno) + sname 3. Step 3 --- Consider cno -> cname, since cno is in X^c and cname is not, we have X^c <- (sno, cno, sname) + cname 4. Step 4 --- Again, consider sno -> sname but this does not change X^c. 5. Step 5 --- Again, consider cno -> cname but this does not change X^c. • Therefore X+ = X^c = (sno, cno, sname, cname).
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN FD & Relationship • Functional dependencies also arise in relationships. • Let C be the primary key of an entity and D be the primary key of another entity. • Let the two entities have a relationship. • If the relationship is one-to-one: – C -> D – D -> C • If the relationship is many-to-one: – C -> D but not D -> C • For many-to-many relationships, no functional dependencies hold. INFORMATICS DEPARTMENT – IT TELKOM CS2343 – RELATIONAL DATABASE DESIGN Examples of FD constraints • Social Security Number determines employee name SSN ENAME • Project Number determines project name and location PNUMBER {PNAME, PLOCATION} • Employee SSN and project number determines the hours per week that the employee works on the project {SSN, PNUMBER} HOURS
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Example - 2 • C is student number and D is subject number, there is no functional dependency between them. If however, we were storing marks and grades in the database as well, we would have – (student_number, subject_number) -> marks – marks -> grades
INFORMATICS DEPARTMENT – IT TELKOM
CS2343 – RELATIONAL DATABASE DESIGN Review • The concept of functional dependency is related to the concept of candidate key of a relation • Therefore any subset X of the attributes of a relation R that satisfies the property that all remaining attributes of the relation are functionally dependent on it (that is, on X), then X is candidate key as long as no attribute can be removed from X and still satisfy the property of functional dependence. • Functional dependence is an important concept and a large body of formal theory has been developed about it. • Once a complete set of functional dependencies has been obtained, we will study how these may be used to build normalised relations.