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

FD and Closure Attribute

The document discusses functional dependencies in database management systems, defining their relationships and types, including trivial, non-trivial, transitive, and join functional dependencies. It also covers properties of functional dependencies, such as reflexivity, augmentation, transitivity, and the process of finding super keys and candidate keys. Additionally, it explains the concept of a canonical cover for functional dependencies, detailing steps to simplify and eliminate redundancy while maintaining the same closure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

FD and Closure Attribute

The document discusses functional dependencies in database management systems, defining their relationships and types, including trivial, non-trivial, transitive, and join functional dependencies. It also covers properties of functional dependencies, such as reflexivity, augmentation, transitivity, and the process of finding super keys and candidate keys. Additionally, it explains the concept of a canonical cover for functional dependencies, detailing steps to simplify and eliminate redundancy while maintaining the same closure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 56

CGB1221 - DATABASE MANAGEMENT SYSTEMS

FUNCTIONAL DEPENDENCIES
– Relationship between one attribute with the other attribute
– Denoted by ->
– X & Y are attribute then X -> Y (We can say X determines Y or Y is
functionally depend on X)
– The left side of FD is known as a determinant, the right side of the
production is known as a dependent.
– If t1.x=t2.x then t1.y=t2.y
FUNCTIONAL DEPENDENCIES
• For example:
• Assume we have an employee table with attributes: Emp_Id, Emp_Name,
Emp_Address.
• Here Emp_Id attribute can uniquely identify the Emp_Name attribute of
employee table because if we know the Emp_Id, we can tell that employee
name associated with it.
• Functional dependency can be written as:
Emp_Id → Emp_Name
• We can say that Emp_Name is functionally dependent on Emp_Id.
FUNCTIONAL DEPENDENCIES
• Full Functional Dependent
A functional dependency X → Y is fully functional if removing any attribute
from X causes the dependency to no longer hold.
FUNCTIONAL DEPENDENCIES
• Partial Functional Dependent
A functional dependency X → Y is fully functional if removing any attribute
from X causes the dependency to no longer hold.
FUNCTIONAL DEPENDENCIES

Primary Key: (Student_ID, Course_ID)


•A student can enroll in multiple courses.
•A course can have multiple students.
•(Student_ID, Course_ID) → Instructor (?)
•Student_ID → Student_Name (?)
•Course_ID → Course_Name (?)
PROPERTTIES OF FUNCTIONAL DEPENDENCIES

– Also called as Armstrong Axioms


– Inference rules are also called as secondary rules derived from Armstrong
axioms
– Reflexivity
• If Y is a subset of X, then X → Y is always true.
✔ Example:
• Consider X = {Student_ID, Name}, and Y = {Student_ID}.
• Since Y ⊆ X, we can say:
{Student_ID, Name} → Student_ID
PROPERTTIES OF FUNCTIONAL DEPENDENCIES

– Augmentation
– If X → Y holds, then XZ → YZ also holds (adding extra attributes doesn't
change dependency).
✔ Example:
• If Student_ID → Name holds,
• Then (Student_ID, Course) → (Name, Course) also holds.
PROPERTTIES OF FUNCTIONAL DEPENDENCIES

– Transitivity
• If X → Y and Y → Z, then X → Z.
✔ Example:
• If Student_ID → Name
• And Name → Address,
• Then we can infer Student_ID → Address
PROPERTTIES OF FUNCTIONAL DEPENDENCIES

– Union
• If X → Y and X → Z, then X → YZ.
✔ Example:
• If Course_ID → Course_Name
• And Course_ID → Instructor,
• Then we can combine as Course_ID → (Course_Name, Instructor)
PROPERTTIES OF FUNCTIONAL DEPENDENCIES

– Decomposition
• If X → YZ, then X → Y and X → Z.
✔ Example:
• If Course_ID → (Course_Name, Instructor),
• Then we can say Course_ID → Course_Name
• And Course_ID → Instructor
PROPERTTIES OF FUNCTIONAL DEPENDENCIES

– Pseudotransitivity
• If X → Y and WY → Z, then WX → Z.
✔ Example:
• If Student_ID → Department
• And (Department, Course) → Instructor,
• Then (Student_ID, Course) → Instructor
PROPERTTIES OF FUNCTIONAL DEPENDENCIES

– Composition (Splitting or Projective Rule)


• If X → Y and WY → Z, then WX → Z.
✔ Example:
• If Student_ID → Department
• And (Department, Course) → Instructor,
• Then (Student_ID, Course) → Instructor
TYPES OF FUNCTIONAL DEPENDENCIES

– TRIVIAL DEPENDENCIES
• Definition: If Y ⊆ X, then X → Y is trivial.
✔ Example:
• (Student_ID, Student_Name) → Student_ID
• Student_ID → Student_ID
TYPES OF FUNCTIONAL DEPENDENCIES

– NON TRIVIAL DEPENDENCIES


• A functional dependency (FD) X → Y is non-trivial if Y is not a subset of X.
In other words, the right-hand side contains attributes that are not already
present in the left-hand side.Here are the functional dependencies:
• 1 Student_ID
1️⃣ → Student_Name (Non-Trivial)
• The Student_Name is not part of Student_ID.
• 2️⃣
(Student_ID, Course_ID) → Student_Name (Non-Trivial)
• The Student_Name is not a part of (Student_ID, Course_ID).
TYPES OF FUNCTIONAL DEPENDENCIES

– TRANSITIVE FUNCTIONAL DEPENDENCIES


• Definition: If X → Y and Y → Z, then X → Z is a transitive dependency.
• Student_ID → Department_ID ✅
🔹 Department_ID → Department_Name ✅
🔹 Student_ID → Department_Name (via transitivity)
TYPES OF FUNCTIONAL DEPENDENCIES

– JOIN FUNCTIONAL DEPENDENCIES


• Definition: A table should be decomposable into smaller tables without losing
information.
✔ Example:
A table (Student_ID, Course_ID, Instructor_ID) should be split into:
• 1️⃣STUDENT_COURSE (Student_ID, Course_ID)
2️⃣COURSE_INSTRUCTOR (Course_ID, Instructor_ID)
CLOSURE OF ATTRIBUTE
• It is a set of attribute that functionally determined by attribute set.
• It can be a single attribute or Attribute Set
• Represented by ‘+’
• Closure of X=X+={}
• Example
• R=(A,B,C,D,E)
• Functional Dependencies
o A->B
o B->C
o C->D
o D->A
CLOSURE OF ATTRIBUTE
• Example
• R=(A,B,C,D,E)
• Functional Dependencies
o A->B
o B->C
o C->D
o D->A
• Closure
– A+={A,B,C,D}
– D+={D,A,B,C}
– E+={E}
– (B,C)+={B,C,D,A)
CLOSURE OF ATTRIBUTE
• Example
• R=(A,B,C,D,E)
• Functional Dependencies
o A->BC (ie A->B,A->C)
o BC->DE (ie. BC->D, BC->E)
o D->F
o CF->G
• Closure
– A+={A,B,C,D,E,F}
– D+={D,F}
– (B,C,D)+={B,C,D,F,G}
FINDING SUPER KEY AND CANDIDATE KEY
• If closure of attribute / set of attribute determines all the attributes of relation
• Example
– R={A,B,C}
– (AB)+={A,B,C} then AB is a super Key
Possible Combination are
ABC
AB
BC
CA
A
B
C
FINDING SUPER KEY AND CANDIDATE KEY
• Example
– R={A,B,C,D,E}
• Functional Dependencies
• A->B
• C->D
• D->E
• Super Key
• (A,B,C,D,E)+=(A,B,C,D,E)
• (A,C,D,E)+=(A,C,D,E,B)
• (A,C,E)+=(A,C,E,B,D)
FINDING SUPER KEY AND CANDIDATE KEY
• Super Key
• (A,B,C,D,E)+=(A,B,C,D,E)
• (A,C,D,E)+=(A,C,D,E,B)
• (A,C,E)+=(A,C,E,B,D)
• (AC)+=(A,C,B,D,E)
• (CE)+=(C,E,D)
• (AE)+=(A,E,B)
• A+=(A,B)
• C+=(C,D,E)
• E+=( E)
Final Super Key is ABCDE,ACDE,ACE,AC
Minimal Key is Candidate key . So AC is Candidate key
FINDING SUPER KEY AND CANDIDATE KEY
• Prime attributes are attributes available in the candidate key
• AC – A and C are candidate key
• To Check for more candidate keys
• Check whether any one of prime attributes are on the RHS of any functional
Dependencies
• If not – there is only one candidate key
• If yes – replace prime attribute in candidate key with corresponding LHS of FD

• Repeat finding superkey and candidate key


FINDING SUPER KEY AND CANDIDATE KEY
• Example
– R={x,y,z,w}
• Functional Dependencies
• x->y
• y->z
• z->x
• Super Key
• (x,y,z,w)+=(x,y,z,w)
• (x,z,w)+=(x,z,w,y)
• (z,w)+=(z,w,x,y)
• (z)+=(z,x,y)
• (w)+=(w)
• Replace with yw
• (yw)+=(y,w,z,x)
FINDING SUPER KEY AND CANDIDATE KEY
• Candidate Key – zw
• Replace with yz
• (yw)+=(y,w,z,x)
• (y)+=(y,z,x)
• (w)+=(w)
• Minimal key – yw is candidate key
• Prime attributes are yw is replaced with xw
• (xw)+=(x,w,y,z)
• (x)+=(x,y,z)
• (w)+=(w)
• Ck is xw prime attributes are x and w, replace with zw
FINDING SUPER KEY AND CANDIDATE KEY
• Practice Problem 1
• R=(A,B,C,D,E)
• FD
– AB->C
– C->D
– B->E

• Practice Problem 2
• R=(A,B,C,D,E,H)
• FD
– A->B
– BC->D
– E->C
– D->A
CANONICAL COVER OF FUNCTIONAL DEPENDENCIES

• Managing a large set of functional dependencies can result


in unnecessary computational overhead. This is where the
canonical cover becomes useful. The canonical cover of a
set of functional dependencies F is a simplified version of F
that retains the same closure as the original set, ensuring no
redundancy.
• An attribute in a functional dependency is considered
extraneous if it can be removed without altering the closure
of the set of functional dependencies.
• An attribute in a functional dependency is considered
extraneous if it can be removed without altering the closure
of the set of functional dependencies.
CANONICAL COVER OF FUNCTIONAL DEPENDIES

• The process of finding the canonical cover of a set of


functional dependencies involves the following steps:
• Step 1: Combine Functional Dependencies with
the Same Left-Hand Side
• If two or more functional dependencies in F have the
same left-hand side, combine them into a single
functional dependency by taking the union of their
right-hand sides.
• Example:
• A→B and A→C become A→BC.
CANONICAL COVER OF FUNCTIONAL DEPENDIES

Step 2: Eliminate Extraneous Attributes


• An attribute is extraneous if removing it does not change
the closure of the functional dependency set. There are two
scenarios:
• Extraneous Attributes on the Left-Hand Side:
• For X→Y, check if any attribute in X can be removed without
affecting the closure.
• To check:
• Remove an attribute A from X to form X′.
• Compute the closure of F with X′→Y
• If the closure remains unchanged, A is extraneous.
CANONICAL COVER OF FUNCTIONAL DEPENDIES

• Extraneous Attributes on the Right-Hand Side:


• For X→Y, check if any attribute in Y can be removed
without affecting the closure.
• To check:
• Remove an attribute B from Y.
• Compute the closure of F with X→Y′, where Y′ is Y
without B.
• If the closure remains unchanged, B is extraneous.
CANONICAL COVER OF FUNCTIONAL DEPENDIES

Step 3: Decompose Functional Dependencies


• If the right-hand side of a functional dependency has
multiple attributes (e.g., X→AB), decompose it into
multiple functional dependencies, each with a single
attribute on the right-hand side.
• Example:
• X→AB becomes X→A and X→B.
CANONICAL COVER OF FUNCTIONAL DEPENDIES

Step 4: Check for Redundant Dependencies


• A functional dependency FD in F is redundant if it can
be removed without changing the closure of F.
• To check:
• Temporarily remove FD from F.
• Compute the closure of the remaining set.
• If the closure is the same as the closure of the original
set, FD is redundant and can be removed.
CANONICAL COVER OF FUNCTIONAL DEPENDIES

Step 5: Verify the Final Canonical Cover


• Ensure that each functional dependency is in its
simplest form:
• The left-hand side has no extraneous attributes.
• The right-hand side contains only one attribute.
• Check that the closure of the canonical cover is the
same as the closure of the original set F.
CANONICAL COVER OF FUNCTIONAL DEPENDIES

• Example 1:

𝐹={𝐴→𝐵𝐶,𝐵→𝐶,𝐴𝐵→𝐶}. Here are the steps to find


• Consider a set of Functional dependencies:

the canonical cover –


• Step 1: Combine Functional Dependencies with
the Same Left-Hand Side
• No two functional dependencies in F have the same
left-hand side, so no changes are needed at this stage.
CANONICAL COVER OF FUNCTIONAL DEPENDIES

Step 2: Eliminate Extraneous Attributes


• Check A→BC :
• The left-hand side A has no extraneous attributes because it’s a single
attribute.
• Check the right-hand side for extraneous attributes:
• Split A→BC into A→B and A→C.
• Now, F={A→B,A→C,B→C,AB→C}.
• Check B→C :
• The left-hand side B has no extraneous attributes (it’s a single attribute).
• No changes are needed.

Checking 𝐴𝐵→𝐶: First, check if 𝐴 or 𝐵 is extraneous.


• Check AB→C :

We can reach 𝐶 without using 𝐴𝐵→𝐶 with other functional dependencies;


therefore, we remove 𝐴𝐵→𝐶.


• Finally, we have {𝐴→𝐵, 𝐴→𝐶, 𝐵→𝐶}.


CANONICAL COVER OF FUNCTIONAL DEPENDIES
• Step 3: Decompose Functional Dependencies
• All functional dependencies in F={A→B,A→C,B→C}
have single attributes on the right-hand side, so no
decomposition is needed.
• Step 4: Check for Redundant Dependencies
• Check A→C :

reached without using it. For example, 𝐴→𝐶 can be


• Check each functional dependency to see if it can be

reached with 𝐴→𝐵 and 𝐵→𝐶. Therefore, 𝐴→𝐶 is


redundant and can be removed.
• Now F={A→B,B→C}.
CANONICAL COVER OF FUNCTIONAL DEPENDIES
• Step 5: Final Canonical Cover
• The final canonical cover is:
• Fc={A→B,B→C}.
• This is the simplified set of functional dependencies
that has the same closure as the original set F.
CANONICAL COVER OF FUNCTIONAL DEPENDIES
• Example 2:
• Given F = { A → BC, B → C, A → B, AB → C }
• Step 1 Reduction: There are two functional
dependencies with the same attributes on the left: A →
BC, A → B are already in their simplest form.
• Step 2 Elimination: In A → BC, C is extraneous
because A → C can be derived from A → B and B → C.
Thus, we reduce it to A → B.
• Step 3 Minimization: No redundant dependencies
remain.
• Hence, the canonical cover is Fc = { A → B, B → C }
CANONICAL COVER OF FUNCTIONAL DEPENDIES
• Example 3:
• Given F = { A → BC, CD → E, B → D, E → A }
• Step 1 Reduction: Each left-hand side of the functional
dependencies is unique and cannot be combined further.
• Step 2 Elimination: None of the attributes on the left or
right sides of any functional dependency are extraneous.
• Step 3 Minimization: No dependencies are redundant.
• Hence, the canonical cover is F = { A → BC, CD → E, B →
D, E → A }.
CANONICAL COVER OF FUNCTIONAL DEPENDIES
• Find the canonical cover
• R=(A,B,C)
• F={A->BC,B->C,A->B,AB->C}
• Find the candidate key
• AB->C, C->D, D->A for the relation R=(A,B,C,D).
NORMALIZATION

• Optimizing relations/tables.
• Avoid Redundancy
• Avoid Anomalies
• Normalization is a process in database design used to eliminate
redundancy and dependency by organizing data into multiple related
tables. It improves data integrity, consistency, and efficiency by reducing
anomalies (insertion, update, and deletion anomalies).
What are Atomic Values?
• Atomic values refer to indivisible, single-valued data elements in a
database table. A column contains atomic values if each cell holds only
one value, rather than multiple values or lists.
NORMALIZATION

• First Normal Form(1NF)


• Second Normal Form(2NF)
• Third Normal Form(3NF)
• Boyce Codd Normal Form(BCNF)
• Fourth Normal Form(4NF)
• Fifth Normal Form(5NF)
NORMALIZATION

• Insertion Anomaly: Insertion Anomaly refers to when


one cannot insert a new tuple into a relationship due
to lack of data.
• Deletion Anomaly: The delete anomaly refers to the
situation where the deletion of data results in the
unintended loss of some other important data.
• Updatation Anomaly: The update anomaly is when
an update of a single data value requires multiple rows
of data to be updated.
NORMALIZATION
NORMALIZATION
NORMALIZATION
NORMALIZATION

• Advantages of Normalization
• Normalization helps to minimize data redundancy.
• Greater overall database organization.
• Data consistency within the database.
• Much more flexible database design.
• Enforces the concept of relational integrity.
NORMALIZATION

• Disadvantages of Normalization
• You cannot start building the database before knowing
what the user needs.
• The performance degrades when normalizing the
relations to higher normal forms, i.e., 4NF, 5NF.
• It is very time-consuming and difficult to normalize
relations of a higher degree.
• Careless decomposition may lead to a bad database
design, leading to serious problems.
NORMALIZATION
• Unnormalized Data
↓ (Removing Repeating Groups)
• 1NF
↓ (Remove Partial Dependencies)
• 2NF
↓ (Remove Transitive Dependencies)
• 3NF
↓ (Make Sure Determinants are Candidate Keys)
• BCNF
↓ (Remove Multivalued Dependencies)
• 4NF
↓ (Remove Join Dependencies)
• 5NF
NORMALIZATION
FIRST NORMAL FORM

• A relation will be 1NF if it contains an atomic value.


• It states that an attribute of a table cannot hold multiple values. It
must hold only single-valued attribute.
• First normal form disallows the multi-valued attribute, composite
attribute, and their combinations.
• Input (Unnormalized Table - UNF)
• Output (1NF Table)
FIRST NORMAL FORM
SECOND NORMAL FORM

• A table is in 2NF if:


1. It is already in 1NF.
2. No partial dependency exists (i.e., no non-key attribute depends on
only a part of the primary key in a composite key).
3. In the second normal form, all non-key attributes are fully functional
dependent on the primary key

• Input (1NF Table - With Partial Dependency):


• Output (2NF Tables - Eliminating Partial Dependencies):
SECOND NORMAL FORM
SECOND NORMAL FORM

You might also like