Skip to content

How to find database closure, candidate code and paradigm?

About 747 wordsAbout 2 min

Big Data

2025-02-27

How To Find Closure

Closure is the set of all attributes directly or indirectly derived from an attribute. Suppose we now know the function dependency set FF of a table and want to find the closure of the table.

  1. Let the attribute set that will eventually become the closure be YY, and initialize YY to XX.

  2. Check each function dependency ABA \rightarrow B in FF. If all attributes in the attribute set AA are in YY, and some attributes in BB are not in YY, add them to YY.

  3. Repeat the second step until no attributes can be added to the attribute set YY.

The final YY is X+X^{+*}.

How To Find A Candidate Key

If the value of a certain attribute group in a relation can uniquely identify a tuple, then the attribute group is called a candidate key.

  1. Find all attributes that do not appear on the right side of FDFD to form an attribute group XX. XX must appear in any candidate key.

  2. Calculate the closure of XX.

  3. If X+=UX^+=U, then XX is the only candidate key, otherwise continue to step 4.

  4. Calculate Y=UX+Y=U-X^+​.

  5. For each subset α\alpha of YY, check whether XαX \alpha is a candidate key (same method as 2,3).

Calculation example

Given R(A,B,C,D,E,G)R(A,B,C,D,E,G), F{DG,CDE,ED,AB}F\{D \rightarrow G, CD \rightarrow E, E \rightarrow D, A \rightarrow B\}.

  1. Find all attributes that do not appear on the right side of FDFD and form an attribute group XX. XX must appear in any candidate code.

X=ACX = AC

  1. Calculate the closure of XX

X+=(AC)+={A,C,B}X^+ = (AC)^+=\{A,C,B\}

  1. If X+=UX^+=U, then XX is the only candidate code, otherwise continue to step 4.

Obviously, the current X+X^+ does not satisfy it, so continue.

  1. Calculate Y=UX+Y=U-X^+.

Y={D,E,G}Y=\{D,E,G\}

  1. For each subset α\alpha of YY, see if XαX \alpha is a candidate code (the method is the same as step 2 and step 3).

(ACD)+={A,C,D,B,G,E}(ACD)^+=\{A,C,D,B,G,E\} ✔️

(ACE)+={A,C,E,B,D,G}(ACE)^+=\{A,C,E,B,D,G\} ✔️

(ACG)+={A,C,G,B}(ACG)^+=\{A,C,G,B\} ✖️

So the candidate keys are {ACD}, {ACE}. The attributes included in any candidate key are called primary attributes.

Lossless Connectivity

To determine whether two tables are lossless links is actually to determine whether their contents are equivalent.

  1. Find the intersection of the two decomposed tables (set as R1R_1 and R2R_2).

  2. Determine whether this intersection is a superkey of R1R_1 or R2R_2 's supercode.

Supercode: A set of one or more attributes, the combination of which allows us to uniquely identify an entity in an entity set.

Preserving Dependencies

To determine whether two tables have preserved dependencies is actually to determine whether the data dependencies are equivalent.

Directly determine whether the attributes on the left and right sides of each functional dependency in the original undecomposed table are in the same decomposed table. That is, whether all derivations F1F_1 that can be constructed in R1R_1 and all derivations F2F_2 that can be constructed in R2R_2 satisfy F1F2=F+F_1 \cup F_2 = F^+​.

Normal Form

1NF

In the relational model RR ​, 1NF is satisfied if and only if all attributes contain only atomic values, that is, each component is an indivisible data item.

2NF

If and only if the relational model RR ​satisfies 1NF, and each non-key attribute is completely dependent on the candidate key, it satisfies 2NF. That is, on the basis of satisfying 1NF, let all attributes depend on the candidate key.

For example: the candidate key is BC, the non-primary attribute is D, and in addition to BC->D, there are also B->D or C->D in the functional dependency. This pattern does not meet 2NF.

3NF

If and only if the relational model RR satisfies 1NF, and no non-key attribute in RR ​transitively depends on the candidate key, it satisfies 3NF. That is, on the basis of 2NF, the indirect dependence of all attributes on the candidate key is eliminated, and all attributes are directly dependent on the candidate key.

Changelog

Last Updated: View All Changelog
  • feat(docs): add new english articles

    On 2/27/25

Keep It Simple