Database three paradigm (NF) __ Database

Source: Internet
Author: User

Database in the optimization of the time we mainly through four aspects of the consideration:

1. The rationality of database design (more on the rationality of the table structure).

2, the structure optimization of SQL statements

3, the data configuration (more for the cache, sacrificing space in exchange for time)

4, in our hardware configuration and operating system options for consideration.

Today, we mainly introduce the rationality of database design, this part:

The rationality of the so-called database table design is mainly to see whether the table we designed follows the three normal paradigms.

First paradigm: Require our data to be atomic and indivisible. In a relational database, the default is to follow our first paradigm.

Second paradigm: On the basis of satisfying the first paradigm, consider our second paradigm: the uniqueness of a record.

The so-called uniqueness is actually mostly in our database set a primary key, avoid duplication.

Third paradigm: On the basis of satisfying the second paradigm, we consider the third paradigm: the information we need, which can be obtained through the association relationship between tables, without the need to add redundant fields of the same content to multiple tables.

From the design of ordinary table, to meet the three paradigms, the basic requirements of database table design.

But there is nothing absolute about everything. Depending on the specific requirements, sometimes we need to do a table design of the inverse paradigm:

For example I have a need:

Two teams, 10 people in each squad, in a competition, I need you to give me a personal total score, and a team's score.

This time if the use of paradigm design is this:

Have you noticed any problems? If not, you have problems in programming habits, only stay in the use of the stage, without thinking.

It is true that we can iterate through the entire team table by writing SQL statements, by ID or a designated team, to get everyone's score added

Finally got the team score. However, this causes us to query the data is too large, you think we need to get all the players score, add up, if the team has thousands of people, I will traverse thousands of times.

This time the inverse paradigm comes in handy, and I also add a score field to the team table.


Add a trigger, and when someone in a team scores plus 1 o'clock, I trigger the Team_grade field on the team table plus 1.

So when we query the team score, we just need to query a piece of data to get the value out. Save a lot of time.

However, it should be noted that in the use of inverse paradigm, it is important to note that in a one-to-many relationship, the similar redundant fields that can be associated must be set on one side, otherwise it becomes superfluous.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.