3.6.1 Database System-Normalization Theory: Problems Existing in Denormalization, Basic Concepts of Normalization Theory, Functional Dependency, Key, Finding Candidate Keys, Finding Candidate Key Examples, Functional Dependency, Armstrong Axiom

3.6.1 Database System-Normalization Theory: Problems Existing in Denormalization, Basic Concepts of Normalization Theory, Functional Dependency, Key, Finding Candidate Keys, Finding Candidate Key Examples, Functional Dependency, Armstrong Axiom

Problems with Denormalization

Normalization is a task in the logic stage. If normalization is not done, some strange problems will appear in the data. It may include: data redundancy, update exception (modification operation consistency problem), insert exception, delete exception.
Please add a picture description
For example, when designing at the beginning, the diagram is convenient, and all the data that can be used will be stored in a table. From the diagram, it can be seen that the table data records repeated department numbers, department names, and department locations.
This system can be abstracted into another relationship, which will be better, so as not to cause data redundancy;
at the same time, if the system changes, you need to update all relevant data, which may be missed;
at the same time, your system depends on Students, in the relational model, the primary key is non-empty and unique. If there are no students in some departments, how to insert this department? An insertion exception will occur;
the student information needs to be deleted after graduation, and the department information will be deleted at the same time, which may cause the department to be lost.

Basic Concepts of Normalization Theory

These concepts are used in paradigm judgment

functional dependencies

Let R(U,F)Y be a relation pattern on attribute U, X and Y are subsets of U, r be any relation of R, if for any two tuples u, v in r, as long as there is If u[X]=v[X], there is u[Y]=v[Y], then it is said that the X function determines Y, or the Y function depends on X, which is recorded as X→Y, and the functional dependence is uniquely determined. For example, X→Y, but Y→X is not acceptable.

X→Y, the left side is called the determinant, and the right side is called the determined factor.

key

Candidate key, candidate key : it can be a multi-attribute set, or there can be multiple candidate keys, uniquely identifying tuples, no redundant primary
key : select a
foreign key from the candidate key : the primary key of other relationships Primary
attributes and non-primary attributes : form candidates The attribute of the code is the main attribute, and the others are non-main attributes

Candidate key

  • Represent the functional dependencies of the relational schema in the form of a "directed graph"
  • Find an attribute with an in-degree of 0, and use this attribute set as a starting point to try to traverse the directed graph. If all nodes in the directed graph can be traversed normally, the attribute set is a candidate key for the relational schema
  • If the attribute set with an in-degree of 0 cannot traverse all the nodes in the graph, it is necessary to try to merge some intermediate nodes (nodes with both in-degree and out-degree) into the attribute set with an in-degree of 0 until This set can traverse all nodes, and the set is a candidate key

For the in-degree and out-degree: In the figure, the in-degree with the arrow flowing in is called the in-degree, and the out-degree with the arrow outflow is called. Combined with the functional dependency set, all those that appear on the left side of the arrow and those that do not appear on the right side are recorded As the in-degree is 0, it is denoted as L, which means the set of attributes with in-degree 0, and those with only in-degree and no out-degree are denoted as R.

When considering the set of candidate keys, the attributes of the L set must be included, and the attributes of the R set must not be included.

Seek candidate key instance

The relational schema P (A, B, C, D, E, F, G, H, I, J) satisfies the following functional dependencies: FD={ABD→E,AB→G,B→F,C→J,CJ→ I, G→H}, looking for candidate codes?

Method :
According to the functional dependence, first find the in-degree and out-degree
L:ABDC
R: E, G, F, J, I, H

According to the derivation of L, see if all attributes (A, B, C, D, E, F, G, H, I, J) can be deduced. ABDC can derive itself, ( A, B, C, D , E
, F , G, H, I, J), and the deduced attributes can be deduced below using
ABD→E, ( A,B,C,D,E ,F,G,H,I,J)
B→F, ( A ,B,C,D,E,F , G,H,I,J)
AB→G, ( A,B,C,D,E,F,G , H,I,J)
G→H, ( A ,B,C,D,E,F,G,H ,I,J)
C→J, ( A,B,C,D,E,F,G,H,I , J )
CJ→I, ( A ,B,C,D,E,F,G,H,I,J )
So, (ABCD) this set is a candidate code.

Represented by a directed graph :
Please add a picture description

functional dependencies

Functional dependency itself is the basic concept of page normalization theory, mainly including partial functional dependency and transitive functional dependency.

Partial functional dependency :
Relational mode: R1 (A, B, C, D)
dependency set: {AB→D, A→C}
The candidate key is (AB). For the candidate key is a composite key, C only depends on Among them, A depends on a part of the candidate key, and C is called partial functional dependency . Only when the candidate key is a collection of multiple attributes will partial functional dependency appear.

Relationship mode: R2 (A, B, C)
dependency set: {A→B, B→C}
from A→B, B→C, A→C can be deduced, and the second is the transfer function dependency

Armstrong's axiom

The relationship pattern R<U,F> has the following inference rules:
A1. Reflexive: If Y⊆X⊆U, then X→Y holds.
A2. Augmentation: If Z⊆U and X→Y, then XZ→YZ holds.
A3. Transitive: If X→Y, Y→Z, then X→Z holds.

According to the three inference rules A1, A2, and A3, the following three rules can be obtained:
Merging rules: from X→Y, X→Z, and X→YZ. (A2, A3)
Pseudo transitive rules: from X→Y, WY→Z, and XW→Z. (A2, A3)
Decomposition rules: from X→Y and Z⊆Y, there is X→Z. (A1, A3)

containment relationship

Contains the symbols ⊇, ⊆, ⫋.

⊆ is contained in sign: A is contained in B - then A is a subset of or equal to B.

is ⊇ containment symbol: A contains B - then B is a subset of A or equal to A.

⫋True inclusion: A is true inclusion in B-then A is a proper subset of B, if B={1, 2}, then A={1} or {2} or the empty set.

definition:

If any element of set A is an element of set B (any a∈A then a∈B), then set A is called a subset of set B, recorded as A⊆B or B⊇A, read as "set A Contained in Set B" or Set B Contains Set A".

That is: ∀a∈A has a∈B, then A⊆B.

Proper subset:
If the set A is a subset of B, and A≠B, that is, at least one element in B does not belong to A, then A is a proper subset of B, which can be written as: A⊊B.

Symbolic language: If ∀a∈A, there is a∈B, and x∈B makes x∉A, then A⊊B.

Guess you like

Origin blog.csdn.net/qq_41929714/article/details/129732855