Three paradigms of database design

A relation in a relational database must meet certain requirements. Different paradigms meet different requirements. The database design paradigm is the specification that the database design needs to meet. Only by understanding the design paradigm of the database can an efficient and elegant database be designed, otherwise the wrong database may be designed.

At present, there are mainly six normal forms: the first normal form, the second normal form, the third normal form, the BC normal form, the fourth normal form and the fifth normal form. The one that meets the minimum requirements is called first normal form, or 1NF for short. On the basis of the first normal form, the second normal form that further meets some requirements is called 2NF for short. And so on for the rest.

Paradigm can avoid data redundancy, reduce database space, and ease the trouble of maintaining data integrity, but it is difficult to operate because it needs to contact multiple tables to get the required data, and the higher the paradigm, the worse the performance. It is more troublesome to weigh whether to use a higher normal form. Generally, in a project, the third normal form is used the most. I think it is enough to use the third normal form, which has good performance and is convenient for data management.

Functional dependency, if the value of a field Y in a table is determined by the value of another field or a group of fields X, it is called Y function depends on X.


First Normal Form (1NF)
definition: If the attributes of each relation r of the relation schema R are inseparable data items, then R is said to be a schema in first normal form.
Simply put, each attribute is an atomic item, indivisible.
1NF is the minimum condition that a relational schema should have. If the database design cannot satisfy the first normal form, it is not called a relational database. Relational normalization in relational database design research is done on top of 1NF.

For example (student information sheet):
student number, name, gender, contact information
20080901 Zhang Sannan email: [email protected], phone: 88886666
20080902 Li Si girl email: [email protected], phone: 66668888

The above table does not conform to the first normal form: the contact information field can be subdivided, so the correct one is:

Student ID Name Gender Email Phone
20080901 Zhang Sannan [email protected] 88886666
20080902 Li [email protected] 66668888

Second Normal Form (2NF)
Definition: If the relational schema R is 1NF, and each non-primary attribute is fully functionally dependent on the candidate key, then R is said to be in second normal form.
Simply put, the second normal form must meet the following conditions: first, the first normal form must be satisfied, and secondly, each non-primary attribute must be fully functionally dependent on a candidate key, or a primary key. That is, each non-primary attribute is determined by the entire primary key function, not by a part of the primary key.

For example (student course selection table):
student course teacher teacher title teaching material classroom class time
Li Si Spring Zhang teacher java lecturer "Spring in simple language" 301 08:00
Zhang San Struts Yang java lecturer "Struts in Action" 302 13:30

Here, teachers, teacher titles, teaching materials, classrooms and class times can be determined through (students, courses), so (students, courses) can be used as the primary key. However, the teaching materials are not completely dependent on (students, courses), and the teaching materials can be determined only by taking out the courses, because a course must specify a certain teaching material. This is called incomplete dependence, or partial dependence. When this happens, the second normal form is not satisfied.

After the revision, the course selection table:
student course teacher teacher title classroom class time
Li Si Spring Zhang teacher java lecturer 301 08:00
Zhang San Struts Yang java lecturer 302 13:30

Curriculum:
Course materials 
Spring "Spring in simple language" 
Struts "Struts in Action"

Therefore, the second normal form can be said to eliminate partial dependencies. Second normal form can reduce insertion exceptions, deletion exceptions and modification exceptions.

Third normal form (3NF)
definition: If the relational schema R is 2NF, and all non-primary attributes in the relational schema R(U, F) have no transitive dependencies on any candidate key, then the relation R is said to belong to the third normal form .  
Simply put, the third normal form must meet the following conditions: first, the second normal form must be satisfied, and secondly, there is no functional dependency between non-primary attributes. Since the second normal form is satisfied, it means that every non-primary attribute is functionally dependent on the primary key. If there is a functional dependency between non-primary attributes, there will be a transitive dependency, which does not satisfy the third normal form.

In the revised course selection table in the above example, one teacher can determine one teacher title. In this way, teachers depend on (students, courses), and teachers' titles depend on teachers, which is called transitive dependency. The third normal form is to eliminate transitive dependencies.

After modification, the course selection table:

Student Course Teacher Classroom Class Time
Li Si Spring Mr. Zhang 301 08:00
Zhang San Struts Yang 302 13:30

Teacher Table:
Teacher Teacher Title
Zhang Teacher Java Lecturer
Yang Teacher Java Lecturer

In this way, the new teacher's professional title has a place to save even when no class is selected, and the teacher's professional title will not be deleted when no one chooses the teacher's class. When modifying the teacher's professional title, just modify the teacher's table.

To put it simply, the
first normal form is atomic, and the fields cannot be divided;
the second normal form is completely dependent, and there is no partial dependency;
the third normal form is that there is no transitive dependency.

 

Reprinted from: http://aijuans.iteye.com/blog/1629645

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326273500&siteId=291194637