On the Three Paradigms of Database

The author is also a rookie. Recently, I was studying databases. I read some detailed explanations of the three major database paradigms on the Internet. It took a lot of effort to figure it out. The following are incorrect expectations. Once I am correct, the key is not to Misleading other novices. That's all the nonsense, and the topic is directly.


The first normal form (1NF) has no duplicate columns

    The so-called first normal form (1NF) means that each column of the database table is an inseparable basic data item, and there cannot be multiple values ​​in the same column, that is, an attribute in an entity cannot have multiple values ​​or duplicate attributes . If there are duplicate attributes, it may be necessary to define a new entity. The new entity consists of duplicate attributes, and there is a one-to-many relationship between the new entity and the original entity.

The above is the official explanation, and my understanding is like this. For example, a table such as the student transcript

Student transcript
id Student name class Type of Exam subject fraction
1 Zhang San 3_2 Of which exam mathematics 89

I have written such a rubbish table before. First of all, this kind of table does not conform to the first normal form.

There can be no more than one class field in the same column. 3_2 The original intention of the data is 3rd grade and 2nd class (this is my personal addition, because the current relational database cannot be designed and does not conform to the first normal form. The reason is that the database does not support Such a setting)

The correct way should be to divide the class into two columns. The fields should be grade and class number 

Second normal form

Is established on the basis of satisfying the first paradigm

The attributes of the required entity are completely dependent on the primary key. The so-called complete dependence means that there can be no attributes that only depend on a part of the primary key. If they exist, then this attribute and this part of the primary key should be separated to form a new entity. The new entity and the original entity are one-to-many. relationship. In order to realize the distinction, it is usually necessary to add a column to the table to store the unique identifier of each instance. In short, the second paradigm is that non-primary attributes are not partially dependent on primary keywords
The general meaning of the above seems to be that two or more transactions cannot be expressed in one table in one table, for example 

Transcript
id Name subject
1 Zhang San mathematics

This is inconsistent. Because name and subject are two different categories or affairs, that is to say, these two cannot be combined into one table. But the following table and the above table are two different things

Transcript
id Name_ID Subject_ID fraction
1 34 2 89
The above table is in line with the second normal form and can be combined with this example  

The attributes of the required entity are completely dependent on the primary key. The so-called complete dependence means that there can be no attributes that only depend on a part of the primary key. If it exists, then this attribute and this part of the primary key should be separated to form a new entity, and there is one-to-many between the new entity and the original entity After thinking about the relationship, you should know what it is talking about.
Third Normal Form (3NF) To 
satisfy the third normal form, you must first satisfy the second normal form. In short, the third normal form requires that a database table does not contain non-primary key information that is already contained in other tables.
First come a non-compliant example
 
  
  
Student_ID Name age school School phone
1 Zhang San 14 Lantian Primary School XXX
This is similar to the second paradigm. My understanding is that based on the second paradigm, when filtering or reviewing, the above school information and student information are on the same table. It feels a bit reluctant, and there is another one that is fatal. The hidden danger is that if the name of the school is changed or the phone number of the school is changed, what will happen, in that case, the number of data to be modified will be more.
The modification that conforms to the 3 paradigm should change the above table into two tables, which is to make a table of school information separately, and combine the above 3 paradigms below to make a data table that I still feel qualified for reference by novices. Of course, it only considers how to meet the requirements of the 3 paradigm, and does not consider the practical application.
 
  
  
Student Information Form
Student_ID Name age  
1 Akari 14  
School Information Form
School_ID School_name School_phone
1 Lantian Primary School XXX
 
  
  
Chart of accounts
Subject_ID subject
1 Language
2 mathematics
Exam Type Table
Exam Type-ID Types of
1 Of which exam
2 Final exam
Test score sheet
ID School_ID Student_ID Exam Type_ID Subject_ID examination time Test score
1 2 2 1 2 xxx 90
The advantage of establishing so many tables is that it is modified and extensible. For example, if you want to increase the test type, you only need to rewrite the test type table. (But the more tables are not the better, for example, the student information table name and Build two tables for ages, so querying them will bring unnecessary trouble), the 3 paradigm itself is not a definition, she should be the experience gathered by developers in actual work, and her rationality is the experience It can stand the test. Finally, I hope this half-copy manuscript can be helpful.
 
 




Guess you like

Origin blog.csdn.net/jia13475881149/article/details/59481975