Database Principles and Applications (SQL)——3. Relational Data Theory (Functional Dependency, Closure, Minimum Set of Functional Dependent Sets, Normalization --- Paradigm )


come on!

Don't stop running,

Don't look back,

There is no way of coming,

The only thing worth looking forward to is the distance. 


Relational data theory is the theoretical basis of relational databases .

Provides criteria for database design ,

is a guide to designing relational databases .

Data storage exceptions (because of data dependencies) - data redundancy, inconsistency, insertion exceptions, deletion exceptions

S(NO, NAME, SEX, COUR, DEGR);

Student table (student number, name, gender, course, grade);

Data redundancy : - a student takes multiple courses, which leads to repeated storage of the student's name (NAME) and gender (SEX);

Inconsistency : Due to data storage redundancy, when some data items are updated, some fields may be modified, while other fields may not be modified, resulting in inconsistency of stored data;


Insertion exception : If a student does not take a course, his (NO, NAME, SEX) information cannot be inserted because COUR is empty, and the relational data schema stipulates that the primary key cannot be empty or partially empty. This is an insertion exception ;


Deletion exception : When all student grades are to be deleted, all (NO, NAME, SEX) are also deleted, which is the deletion exception.

 Data storage exceptions are due to data dependencies, and the vast majority of data dependencies are functional dependencies! ! !

Functional dependence: X function determines Y, or Y function depends on X, it is recorded as X→Y;

        Complete functional dependency : Y function depends on the entire X, denoted as X--f-->Y

        Partial functional dependence : Y function depends on a proper subset of X, denoted as X--p-->Y;

        Transfer function dependence : X→Y, Y→Z, and Y—\→X, ZY≠∅, YX≠∅, then Z is called transitively dependent on X, denoted as X--t-->Z.

Functional dependency axiom - Armstrong axiom;

Reflexivity: if Y⊆X, then X→Y;

        Augmentation: If X→Y, then XZ→YZ;

                Transitivity: If X→Y, Y→Z, then X→Z;

Composition rule: if X→Y, X→Z, then X→YZ;

        Decomposition rules: if X→YZ, then X→Y, X→Z;

                Pseudo-transitive rule: If X→Y, YW→Z, then XW→Z.

 There are three kinds of relationships between attributes, but functional dependencies do not exist in every relationship.


If there is a " 1:1 " relationship between X and Y (like a school and a principal), then there is a functional dependency: X→Y and Y→X

If there is an " m:1 " relationship between X and Y (such as student number and name), then there is a functional dependency: X→Y. (Student number determines the name)


If there is an " m:n " relationship between X and Y (like Student and Course), then there is no functional dependency between X and Y.

 There is a relation schema R(U), and F is its functional dependency set, then all the functional dependencies deduced from F by Armstrong’s axiom X→Ai’s attribute set of Ai is the attribute closure of X, denoted as X+.

The minimum set of functional dependencies: For a given functional dependency F, when the following conditions are met, it is called the minimum set of F, denoted as F';     

         (1) The right part of each dependency of F is a single attribute;
         (2) For any functional dependency X→A in F, F'-{X-A} is not equivalent to F';
         (3) For any X→A in F and a proper subset Z(F'-{X→A})U{Z→A} of F is not equivalent to F'.

Condition (2) ensures that there is no redundant functional dependency in F;

Condition (3) ensures that there are no redundant attributes on the left side of each functional dependency in F;

        First Normal Form (1NF) : Suppose R is a relational schema, and R belongs to the first normal form if and only if the value range of each attribute A in R contains only atomic items, that is, indivisible data items. The first normal form cannot rule out problems such as data redundancy and update exceptions, because there may be partial functional dependencies.

        Second Normal Form (2NF) : Suppose R is a relational schema, R belongs to the second normal form if and only if R is 1NF, and each non-primary attribute is completely functionally dependent on the primary key. Second normal form may also have problems such as data redundancy and update exceptions, because there may be transitive functional dependencies.

        Third Normal Form (3NF) : Suppose R is a relational schema, R belongs to the third normal form if and only if R is 2NF, and each non-primary attribute is non-transfer function dependent on the primary key.

        BC Normal Form (BCNF) : Suppose R is a relational schema, F is its dependency set, and R belongs to BCNF if and only if each dependent determinant in F must contain a candidate keyword of R.

        Fourth Normal Form (4NF) : Given a relational schema R and its attributes A and B, for a given value of A, there is a set of B attribute values ​​corresponding to it, and has no relationship with other attributes (RAB), then it is called "Multiple values ​​of B depend on A" or "multiple values ​​of A determine B", denoted as A→→B.

Decomposition of Relational Schemas: Lossless Connectivity, Functional Dependency Preservation
 

        Lossless connectivity : when decomposing a relational schema, any legal relational instance in the original relational schema should be able to recover through natural connection operations after decomposing.

        Functional dependency retention : Let a decomposition of the relational schema R be p={R1, R2,....Rk}, F is the dependency set of R, if F is equivalent to ПR1(F)U ПR2(F)U .. .U ПRk(F), then the decomposition of p is said to be dependency preserving.


        A lossless-connectivity decomposition is not necessarily dependency-preserving; likewise, a dependency-preserving decomposition is not necessarily lossless-connectivity.

The decomposition of relational schemas and the combination of paradigms are also a very complicated issue! !

It's really complicated! !

Guess you like

Origin blog.csdn.net/qq_64552181/article/details/128207646