Relational Database paradigm

Source: Internet
Author: User
Tags dname

1NF ):In each specific relational R in relational mode r, if each attribute value is the smallest data unit that cannot be further divided, R is called the relationship of the first paradigm. For example, the employee number, name, and phone number form a table (a person may have an office phone number and a home phone number). There are three methods to standardize 1NF:
The first is to repeat the employee ID and name. In this way, the keyword can only be a phone number.
Second, the employee number is a keyword. The phone number is divided into two attributes: the phone number of the organization and the residential phone number.
Third, the employee number is a keyword, but each record must have only one phone number.
The first method is the least desirable of the above three methods. The last two cases are selected based on the actual situation.

2NF ):If all the non-master attributes in the relational mode R (U, F) depend entirely on any candidate keyword, the relational R belongs to the second paradigm.
For example, in the Course Selection relation SCI (SNO, CNO, GRADE, and CREDIT), SNO indicates the student ID, CNO indicates the course number, GRADEGE indicates the score, and CREDIT indicates the CREDIT. The preceding condition indicates a combination of keywords (SNO, CNO)
There are the following problems when using the above link mode in applications:
A. data redundancy. Assume that 40 students take the same course and 40 credits are repeated.
B. The update is abnormal. If the credits of a course are adjusted, the corresponding CREDIT values of the corresponding tuples must be updated, and the credits of the same course may be different.
C. Insert exceptions. For example, if you plan to open a new course, because no one takes the course or has no student ID keyword, you can only save the course and credits after someone takes the course.
D. Deletion exception. If the student has completed the course, the electives will be deleted from the current database. Some new students have not yet taken the course, so the course and credits cannot be saved.
Cause: the non-Keyword attribute CREDIT only depends on CNO, that is, the CREDIT part depends on the combined keyword (SNO, CNO) rather than the full dependency.
Solution: It is divided into two relational modes: SC1 (SNO, CNO, GRADE), C2 (CNO, CREDIT ). The new relationship includes two relational modes, which are connected by the external keyword CNO in SC1. When necessary, they are naturally connected, restoring the original relationship.

3NF ):If all the non-primary attributes in the relational mode R (u, f) do not transmit trust to any candidate keywords, the relational R belongs to the third paradigm.
For example, each attribute of S1 (SNO, sname, DNO, dname, location) represents a student ID,
Name, Department, Department name, and Department address.
The SNO keyword determines the attributes. Because it is a single keyword, there is no part of the dependency problem, it must be 2nf. However, there must be a lot of redundancy in this relationship. The attributes DNO, dname, and location of the student will be stored, inserted, deleted, and modified repeatedly.
Cause: A dependency is transmitted in the link. That is, Sno-> DNO. DNO-> SnO does not exist, DNO-> location. Therefore, the key Liao SnO decides to implement the location function by passing the dependency Sno-> location. That is to say, SnO does not directly determine the non-primary attribute location.
Solution: the transfer dependency cannot be left in each link mode.
Solution: There are two relationships: S (SNO, sname, DNO), D (DNO, dname, location)
Note: The outer keyword DNO cannot be found in link S. Otherwise, the relationship is lost.

Bcnf: If all attributes (including primary and non-primary attributes) of the relational mode R (u, f) do not pass any candidate keywords dependent on R, therefore, relational R belongs to bcnf. Or relational mode R. If each deciding factor contains a keyword (rather than a keyword), then the relational mode of rcnf.
For example, the component management relationship model WPE (wno, PNO, Eno, qnt) lists the Warehouse number, accessory number, employee number, and quantity respectively. The following conditions are met:
A. a warehouse has multiple employees.
B. One employee only works in one warehouse.
C. Special personnel are responsible for one type of accessories in each warehouse, but one person can manage several types of accessories.
D. Parts of the same model can be placed in several warehouses.
Analysis: QNT cannot be determined by the above PNO, and is determined by the combination attribute (WNO, PNO). function dependencies (WNO, PNO)-> ENO exist. A person is responsible for one type of accessories in each warehouse, and one person can manage several types of accessories. Therefore, the owner can be determined only by the combination attribute (WNO, PNO) -> ENO. Because an employee only works in one warehouse, there is ENO-> WNO. As a type of accessories in each warehouse is the responsibility of a person, while an employee only works in one warehouse, there are (ENO, PNO)-> QNT.
Find the candidate keyword, because (WNO, PNO)-> QNT, (WNO, PNO)-> ENO, so (WNO, PNO) can determine the entire tuples, is a candidate keyword. Based on ENO-> WNO, (ENO, PNO)-> QNT, the entire tuples (ENO, PNO) can also be determined as another candidate keyword. The ENO, WNO, and PNO attributes are both primary attributes and only one non-primary attribute QNT. It fully depends on any candidate keyword and is directly dependent on the function. Therefore, the relational mode is 3NF.
Analyze the main attributes. Because ENO-> WNO, the main attribute ENO is the deciding factor of WNO, but it is not a keyword, but only a part of the combination keyword. This results in the dependency of the master attribute WNO on another candidate keyword (ENO, PNO), because (ENO, PNO)-> ENO, but in turn does not exist, p-> WNO, so (ENO, PNO)-> WNO is also a transfer dependency.
Although there is no dependency on the transfer of non-primary attributes to candidate key Liao, the transmission dependency of primary attributes on candidate keywords can also be troublesome. For example, a new employee is assigned to a warehouse but is currently in the internship phase and is not independently responsible for the management of certain accessories. The link cannot be inserted because a portion of PNO is missing. If an individual changes to safety regardless of accessories, the employee will also be deleted when the accessories are deleted.
Solution: divide it into the management EP (ENO, PNO, QNT), the keyword is (ENO, PNO), the job EW (ENO, WNO), and the keyword is ENO
Disadvantage: the persistence of function dependencies after decomposition is poor. In this example, due to decomposition, the function dependency (wno, PNO)-> Eno is lost, and thus the original semantics is damaged. It does not show that a part in each warehouse is under the responsibility of a specialist. A component may be managed by two or more people at the same time. Therefore, the decomposed link mode reduces some integrity constraints.

A link is divided into multiple relationships. To make the decomposition meaningful, the minimum requirement is that the original information is not lost after the decomposition. This information includes not only the data itself, but also the mutual constraints between the data represented by function dependencies. The goal of decomposition is to achieve a higher degree of standardization, but at the same time, two problems must be taken into account: lossless connectivity and function dependency persistence. Sometimes it is often impossible to achieve both lossless connectivity and fully maintain functional dependencies. You need to make trade-offs as needed.

There is a relationship between the four paradigms from 1nf to bcnf:
Bcnf contains 3nf and 2nf contains 1nf.

Summary:
Purpose: normalization aims to make the structure more reasonable, eliminate storage exceptions, and minimize data redundancy to facilitate insertion, deletion, and update.
Principles: follow the concept singularity "one thing and one place" principle, that is, a relational model describes a link between an entity or an entity. The essence of standardization is the simplification of concepts.
Method: link mode projection is divided into two or more link modes.
Requirement: The decomposed link mode set should be "equivalent" to the original link mode, that is, after a natural link, the original link can be restored without losing information, and reasonable links between attributes can be maintained.

Note: If a link mode is completed, different link modes can be obtained. That is to say, the decomposition method is not unique. The Minimum Redundancy must be achieved on the premise that the decomposed database can express all information of the original database. Its fundamental goal is to save storage space, avoid data inconsistency, improve the efficiency of relational operations, and meet application requirements. In fact, it is not necessarily required that all models reach bcnf. Sometimes it is easier to query data by deliberately retaining some redundancy. This is especially true for database systems with low update frequency and high query frequency.

In relational databases, in addition to function dependencies, there are also multi-value dependencies and connection dependencies. This puts forward higher standardization requirements such as the fourth and fifth paradigms. Here, we will discuss it later.

Dear friends, what do you think after reading this article? In fact, any book on basic database theory will talk about these things, considering that many netizens come home halfway to make databases. If you have any questions, don't ask me. I 'd like to find a book on relational database theory, which may be of great help to you. The above is the basic theory. Please think about it. Have you considered following the above several paradigms when designing a database? Are there any problems in database design, think about it. What kind of paradigm does the above mentioned violate?
Few of the database designs I have ever seen are in line with the above several paradigms. Generally, the first paradigm can be followed by very few people who fully abide by the second and third paradigms, the followers must be experts in designing databases. There are few opportunities for the BCNF paradigm to appear, and integrity will be damaged. You can ignore it when designing, of course, the shortcomings can be solved through triggers in ORACLE. In the future, when we work together to design, we also hope that you will abide by the above several paradigms.

Source:Http://hi.baidu.com/goylsf/blog/item/5dca5d454b561f3a869473ca.html

Refer:
Relational Database: Normalization
Relational Database: Use the paradigm to create a database

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.