# Canonical Cover of Functional Dependencies in DBMS

Whenever a user updates the database, the system must check whether any of the functional dependencies are getting violated in this process. If there is a violation of dependencies in the new database state, the system must roll back. Working with a huge set of functional dependencies can cause unnecessary added computational time. This is where the canonical cover comes into play. A canonical cover of a set of functional dependencies F is a simplified set of functional dependencies that has the same closure as the original set F.

An attribute of a functional dependency is said to be extraneous if we can remove it without changing the closure of the set of functional dependencies

**Canonical Cover**

**Canonical Cover**

In DBMS, a canonical cover is a set of functional dependencies that is equivalent to a given set of functional dependencies but is minimal in terms of the number of dependencies. The process of finding the canonical cover of a set of functional dependencies involves three main steps:

The first step is to reduce the original set of functional dependencies to an equivalent set that has the same closure as the original set, but with fewer dependencies. This is done by removing redundant dependencies and combining dependencies that have common attributes on the left-hand side.**Reduction:**The second step is to eliminate any extraneous attributes from the left-hand side of the dependencies. An attribute is considered extraneous if it can be removed from the left-hand side without changing the closure of the dependencies.**Elimination:**The final step is to minimize the number of dependencies by removing any dependencies that are implied by other dependencies in the set.**Minimization:**- To illustrate the process, let’s consider a set of functional dependencies: A -> BC, B -> C, and AB -> C. Here are the steps to find the canonical cover:
We can reduce the set by removing the redundant dependency B -> C and combining the two remaining dependencies into one: A -> B, A -> C.**Reduction:**We can eliminate the extraneous attribute B from the dependency A -> B, resulting in A -> C.**Elimination:**We can minimize the set by removing the dependency AB -> C, which is implied by A -> C.**Minimization:**- The resulting canonical cover for the original set of functional dependencies is A -> C.

A canonical cover F_{c} of a set of functional dependencies F such that all the following properties are satisfied:

- F logically implies all dependencies in F
_{c}. - F
_{c}logically implies all dependencies in F. - No functional dependency in F
_{c}contains an extraneous attribute. - Each left side of a functional dependency in F
_{c}is unique. That is, there are no two dependencies Î±_{1}â†’ Î²_{1}and Î±_{2}â†’ Î²_{2}in such that Î±_{1}â†’_{ }Î±_{2}.

The canonical cover is useful because it provides a simplified representation of the original set of functional dependencies that can be used to determine the key, superkey, and candidate key for a relation, as well as to check for normalization violations and perform other database design tasks.

## How to Find Canonical Cover?

Below mentioned is the algorithm to compute canonical cover for set F.

Repeat

1. Use the union rule to replace any dependencies in Î±_{1}â†’ Î²1 and Î±_{2}â†’ Î²_{2}with Î±_{1}â†’ Î²_{1}Î²_{2}

2. Find a functional dependency Î± â†’ Î² with an extraneous attribute either in Î± or in Î².

3. If an extraneous attribute is found, delete it from Î± â†’ Î².until F does not change

**Example 1:**

Consider the following set * F* of functional dependencies: F= { A â†’ BC, B â†’ C A â†’ B, AB â†’ C }. Below mentioned are the steps to find the canonical cover of the functional dependency given above.

** Step 1:** There are two functional dependencies with the same attributes on the left: A â†’ BC, A â†’ B. These two can be combined to get A â†’ BC. Now, the revised set F becomes F= { A â†’ BC, B â†’ C, AB â†’ C}.

** Step 2:** There is an extraneous attribute in AB â†’ C because even after removing AB â†’ C from the set F, we get the same closures. This is because B â†’ C is already a part of F. Now, the revised set F becomes: F= { A â†’ BC, B â†’ C }

** Step 3:** C is an extraneous attribute in A â†’ BC, also A â†’ B is logically implied by A â†’ B and B â†’ C (by transitivity). F= { A â†’ B B â†’ C }

** Step 4:** After this step, F does not change anymore. So, Hence the required canonical cover is, F

_{c }= { A â†’ B, B â†’ C}

**Example 2:**

Consider another set F of functional dependencies: F={ A â†’ BC, CD â†’ E, B â†’ D, E â†’ A }

- The left side of each functional dependency in F is unique.
- None of the attributes on the left or right side of any functional dependency is extraneous (Checked by applying the definition of extraneous attributes on every functional dependency).
- Hence, the canonical cover F
_{c}is equal to F.

** Note:** There can be more than one canonical cover F

_{c }of a set F of functional dependencies.

**How to Check Whether a Set of FD’s F Canonically Covers Another Set of FD’s G?**

**How to Check Whether a Set of FD’s F Canonically Covers Another Set of FD’s G?**

Consider the following two sets of functional dependencies: F = { A â†’ B, AB â†’ C, D â†’ A, CD â†’ E } G = { A â†’ B, CD â†’ AB } Now, we are required to find out whether one of these f.d.’s canonically covers the other set of f.d.’s. This means, we need to find out whether F canonically covers G, G canonically covers F, or none of the two canonically cover the other. To find out, we follow the following steps:

- Create a singleton right-hand side. This means the attributes to the right side of the f.d. arrow should all be a singleton. The functional dependency D â†’ AC gets broken down into two functional dependencies, D â†’ A and D â†’ C. F = { A â†’ B, AB â†’ C, D â†’ A, D â†’ C, D â†’ E }
- Remove all extraneous attributes. Consider any functional dependency XY â†’ Z. If X in itself can determine Z, then the attribute Y is extraneous and can be removed. As we can see, the occurrence of extraneous attributes is possible only in those functional dependencies where there is more than one attribute in the LHS. So, consider the functional dependency AB â†’ C. Now, we must find the closures of A and B to find whether any of these is extraneous. [A]
^{+}=AB, [B]^{+}=B As we can see, B can be determined from A. This means we can remove B from the functional dependency AB â†’ C. F = { A â†’ B, A â†’ C, D â†’ A, D â†’ C, D â†’ E } - Remove all redundant functional dependencies. Check all f.d.’s one by one, and see if by removing an f.d. X â†’ Y, we can still find out Y from X by some other f.d. A more formal way to state this finds [X]
^{+ }without making use of the f.d. we are testing and check whether Y is a part of the closure. If yes, then the f.d. is redundant. Here, when checking for the f.d. D â†’ C, we observe that even after hiding it, the closure of D contains C. This is because we can obtain C from D by the combination of two other f.d.’s D â†’ A and A â†’C. So, â†’ C is redundant. F = { A â†’ B, A â†’C, D â†’ A , D â†’ E }

**Now, checking F this time**

- Create a singleton right-hand side. This means the attributes to the right side of the f.d. arrow should all be a singleton. G = { A â†’ B, A â†’ C, D â†’ A, D â†’ B }
- Remove all extraneous attributes. Since the RHS of all f.d.’s contains only 1 attribute, no extraneous attribute is possible.
- Remove all redundant functional dependencies. By looping over all f.d.’s and checking the closure of the LHS in all cases, we observe that the f.d. D â†’ B is redundant as it can be obtained through a combination of 2 other f.d.’s, D â†’ A and A â†’ B. G = { A â†’ B, A â†’ C, D â†’ A }

Now, since all f.d.’s of G are already covered in F, we conclude that ** F covers G**.

## Features of the Canonical Cover

The canonical cover is the smallest set of dependencies that can be derived from a given set of dependencies, i.e., it has the minimum number of dependencies required to represent the same set of constraints.**Minimal:**The canonical cover preserves all the functional dependencies of the original set of dependencies, i.e., it does not lose any information.**Lossless:**The canonical cover is unique, i.e., there is only one canonical cover for a given set of dependencies.**Unique:**The canonical cover is deterministic, i.e., it does not contain any redundant or extraneous dependencies.**Deterministic:**The canonical cover helps to reduce data redundancy by eliminating unnecessary dependencies that can be inferred from other dependencies.**Reduces data redundancy:**The canonical cover helps to improve query performance by reducing the number of joins and redundant data in the database.**Improves query performance:**The canonical cover makes it easier to modify, update, and delete data in the database by reducing the number of dependencies that need to be considered.**Facilitates database maintenance:**

## FAQs on Canonical Cover

### 1. What is a functional dependency?

**Answer:**

Functional dependency is basically a relationship between the Primary Key and Non-Key Attributes of the database.

### 2. What is a Canonical Cover in Functional Dependency?

**Answer:**

A canonical cover for a set of functional dependencies F is such that F implies all dependencies together and dependencies are also implied in F.

### 3. Is canonical cover unique?

**Answer:**

No, a functional dependency can have multiple canonical covers.