Introduction to Database Systems (Chapter 6)-Relational Data Theory

1. Raising the question

For a specific problem, how to construct a database schema suitable for it, that is, how to construct several relational schemas, what attributes each relation is composed of, and so on. This is a problem of database design, to be precise, it is a problem of logical design of relational databases.
-------------------------------------------------- ----------Solution: A tool for database logic design-relational database theory.

Formal definition of relational model

In the second chapter, we talked about the formal definition of the relationship model, here is a review.

Previously defined

The relational model consists of five parts, which is a five-tuple:
R(U, D, DOM, F)

  • The relation name R is a symbolic tuple semantics
  • U is a set of attributes
  • D is the domain from which the attributes in the attribute group U come from
  • DOM is the mapping of attributes to domains
  • F is a set of data dependencies on attribute group U
This chapter

Since D and DOM have little relationship with pattern design, in this chapter, the relational pattern is regarded as a triple: R<U,F>
If and only if a relation r on U satisfies F, r is called the relational pattern A relationship of R<U,F>
As a two-dimensional table, the relationship must meet one of the most basic conditions: each component must be an inseparable data item. The relational model that satisfies this condition belongs toFirst Normal Form (1NF)

Data dependence

Data dependency is a constraint relationship between the internal attributes of a relationship and the attributes. This kind of constraint relationship is the correlation between data reflected by whether the values ​​of the attributes are equal or not.
The most important data dependencies are functional dependencies and multi-value dependencies

Functional dependency

Functional dependence is ubiquitous in our lives. For example, to describe the relationship of a student, there can be a student number (sno), name (sname), and department name (sdept). Since a student number corresponds to only one student, and a student only studies in one department, when the student number is determined, the student's name and the value of the department are determined. This relationship of attributes is similar to y=f(x) in mathematics. When the independent variable x is determined, the value of y is also determined. Similarly, sname = f(sno), sdept=f(sno), recorded as sno->sname, sno->sdept.

This single mode of functional dependence may have the following problems in actual use: data redundancy, update exceptions, insert exceptions, delete exceptions, etc. Therefore, this model needs to be improved. The following section will discuss the transformation model and standardization.

2. Standardization

Functional dependency

Functional dependency

Definition: Let R(U) be a relational pattern on an attribute set U, and X and Y are subsets of U. If for any possible relationship r of R(U), it is impossible for two tuples in r to have equal attribute values ​​on X, but unequal attribute values ​​on Y, it is said that "X function determines Y" or "The Y function depends on X", denoted as X→Y.
Insert picture description here

Functional dependency is a concept of semantic category, and a functional dependency can only be determined based on the semantics of the data. For example, the functional dependency of "name→age" can only be established if the same celebrity is not allowed

Functional dependency does not refer to the constraint conditions satisfied by one or some relationship instances of the relational pattern R, but refers to the constraint conditions that all relationship instances of R must satisfy

Trivial functional dependency Non-trivial functional dependency

X → Y, but X → Y is called Y⊈X nontrivial functional dependencies .
X→Y, but Y⊆X means that X→Y is a trivial functional dependency .
Insert picture description here

For any relational model, trivial functional dependence is bound to be established, and it does not reflect the new semantics. Unless otherwise stated, we always discuss non-trivial functional dependencies.

If the X → Y, then X is called function-dependent determinants (Determinant).
If X→Y, Y→X, it is denoted as X←→Y.
If Y does not depend on X as a function, it is written as X↛Y.

Full functional dependency and partial functional dependency

Insert picture description here

Transfer function dependency

Insert picture description here

Note: If Y→X, that is, X←→Y, then Z depends directly on X instead of transfer function dependence.

code

Insert picture description here
Insert picture description here
Insert picture description here

Paradigm

Insert picture description here
Insert picture description here

1NF

Insert picture description here
Simply put, there is no table in the table.

2NF

Insert picture description here
Insert picture description here
Figure 1 Problem optimization:
Insert picture description here

3NF

**Definition: Suppose the relational pattern R<U,F>∈1NF, if such code X, attribute group Y and non-primary attribute Z (Z ⊇ Y) do not exist in R, such that X→Y and Y→Z are established, If Y ↛ X does not hold, it is said that R<U,F> ∈ 3NF.  **
Insert picture description here

BCNF

Insert picture description here
Insert picture description here

Multi-valued dependency

4NF

Insert picture description here

Standardization summary

Insert picture description here
Insert picture description here

3. Popular understanding

Insert picture description here
Relational data theory is actually to provide theoretical support for database design. It is quite difficult to understand the theory only through the book. It is recommended to read this article https://www.cnblogs.com/yanggb/p/10849850.html for general understanding.

Guess you like

Origin blog.csdn.net/qq_41262903/article/details/106169953