Three paradigms of databases

Source: Internet
Author: User

Reprinted URL: http://www.blogjava.net/hijackwust/archive/2007/10/21/154793.html

 

Three paradigms of databases

1n: attributes in relational R are inseparable.
2N: On the basis of 1N, each non-primary attribute fully depends on the code.
3n: Based on 2n, each non-master attribute does not depend on code or code.
1n
| Removes some function dependencies of non-primary attributes on codes.
2N
| Removes the code transfer function dependency of non-primary attributes
3n
| Removes the code-related part of the primary attribute and the function-based transmission.
Bcnf
| Eliminates non-trivial and non-function-dependent multi-value Dependencies
4N

Simple Description:
The requirements of the third paradigm are as follows:
1. Each column has only one value.
2. Each row can be differentiated.
3. Each table does not contain non-primary keywords that other tables already contain.
If each of the two tables meets the three paradigm, the two tables also meet the three paradigm.

From: http://www.cublog.cn/u/23975/showart.php? Id = 391210

The design paradigm of databases is the specifications that need to be met by database design. databases that meet these specifications are concise and have clear structures. At the same time, there will be no insert or delete operations) and update operations are abnormal. On the contrary, it is a mess, which not only creates troubles for database programmers, but also features an ugly face. It may store a large amount of unnecessary redundant information.
Is the design paradigm hard to understand? No, we certainly cannot understand and remember the mathematical formulas given to us in university textbooks. Therefore, many of us simply do not follow the paradigm to design databases.
In essence, the design paradigm can be clearly stated in an image and concise discourse, and it is clear. This article will give a general description of the paradigm, and explain how to apply these paradigms to practical engineering using the database of a simple forum designed by the author as an example.

Paradigm description
1nf: fields in the database table are single attributes and cannot be divided. This single attribute is composed of basic types, including integer, real number, complex type, logical type, and date type.
For example, the following database tables conform to the first paradigm:

Field 1 Field 2 Field 3 Field 4
? ? ? ?

Such database tables do not conform to the first paradigm:

Field 1 Field 2 Field 3 Field 4
? ? Field 3.1 Field 3.2 ?

Obviously, in any current Relational Database Management System (DBMS), dummies cannot make databases that do not conform to the first paradigm, because these DBMS do not allow you to divide one or more columns of a database table into two or more columns. Therefore, it is impossible for you to design a database that does not conform to the first paradigm in the existing DBMS.
2nf ): the database table does not have some function dependencies between non-Keyword fields and any candidate keyword fields (some function dependencies refer to the condition where some fields in the composite keywords determine non-Keyword fields ), that is, all non-Keyword fields depend entirely on any set of candidate keywords.
Assume that the course selection relation table is selectcourse (student ID, name, age, course name, score, and credits), and the keywords are combined keywords (student ID, course name), because the following deciding relation exists:
(Student ID, course name) → (name, age, score, credits)
This database table does not meet the second paradigm because of the following decision relationships:
(Course name) → (credits)
(Student ID) → (name, age)
That is, fields in the combined keywords determine non-keywords.
Because 2nf is not met, this course selection relation table has the following problems:
(1) data redundancy:
The same course is selected by N students, and "Credits" are repeated for n-1 times. The same student takes m courses, and the name and age are repeated for m-1 times.
(2) Update exception:
If the credits of a course are adjusted, the "Credits" value of all rows in the data table must be updated. Otherwise, different credits may occur for the same course.
(3) insertion exception:
For example, if you want to open a new course, no one will take the course. In this way, the course name and credits cannot be recorded in the database because the "student ID" keyword is not yet available.
(4) Deletion exception:
Assuming that a group of students have completed their electives, These electives should be deleted from the database table. However, the course name and credit information are also deleted. Obviously, this will also cause insertion exceptions.

Change the selectcourse table to the following three tables:
Student: Student (student ID, name, age );
Course: Course (Course name, credits );
Course Selection relationship: selectcourse (student ID, course name, score ).
Such database tables conform to the second paradigm, eliminating data redundancy, update exceptions, insertion exceptions, and deletion exceptions.
In addition, all database tables with single keywords comply with the second paradigm, because it is impossible to have a combination of keywords.
Third Paradigm (3nf): Based on the second paradigm, if there is no transfer function dependency for any candidate keyword segment in the data table, it complies with the third paradigm. The so-called pass function dependency refers to the existence of "A → B → C" decision relationship, then the C transfer function depends on. Therefore, database tables that meet the third paradigm should not have the following dependency:
Keyword field → non-Keyword field X → non-Keyword field y
Assume that the student relationship table is student (student ID, name, age, school, school location, school phone number), and the keyword is single keyword "student ID", because the following decision relationship exists:
(Student ID) → (name, age, school, school location, school phone number)
This database complies with 2nf but does not comply with 3nf because of the following decision relationships:
(Student ID) → (school location, school phone number)
That is, the transfer function dependency of the non-Keyword section "school location" and "college phone" on the keyword section "student ID" exists.
It can also cause data redundancy, update exceptions, insertion exceptions, and deletion exceptions. You can analyze and learn this information on your own.
The student relationship table is divided into the following two tables:
Student (student ID, name, age, school );
School: (school, location, phone number ).
Such database tables conform to the third paradigm, eliminating data redundancy, update exceptions, insertion exceptions, and deletion exceptions.
Bois-cell Paradigm (bcnf): Based on the third paradigm, if no field in the database table is dependent on the transfer function of any candidate keyword segment, it complies with the third paradigm.
Assume that the warehouse management relation table is storehousemanage (warehouse ID, storage item ID, administrator ID, quantity), and one administrator works only in one warehouse. One warehouse can store multiple items. This database table has the following decision relationships:
(Repository ID, storage item ID) → (administrator ID, quantity)
(Administrator ID, storage item ID) → (warehouse ID, quantity)
Therefore, both (repository ID, storage item ID) and (administrator ID, storage item ID) are candidate Keywords of storehousemanage, and the unique non-Keyword segments in the table are quantity, it conforms to the third paradigm. However, the following decision relationships exist:
(Repository ID) → (administrator ID)
(Administrator ID) → (repository ID)
That is, the keyword segment determines the keyword segment, so it does not conform to the bcnf paradigm. It has the following exceptions:
(1) Deletion exception:
When the respiratory is cleared, all the "Storage item ID" and "quantity" information are deleted, and the "warehouse ID" and "administrator ID" information are also deleted.
(2) insertion exception:
When a Warehouse does not store any items, an administrator cannot be assigned to the warehouse.
(3) Update exception:
If the repository is changed to an administrator, the administrator ID of all rows in the table must be modified.
Break down the warehouse management relationship table into two Relational Tables:
Warehouse Management: storehousemanage (warehouse ID, administrator ID );
Repository: storehouse (warehouse ID, storage item ID, quantity ).
Such database tables conform to the bcnf paradigm and eliminate deletion, insertion, and update exceptions.

 

 

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.