Detailed explanation of 1NF, 2NF, 3NF, BCNF database paradigm

 

Foreword

The database paradigm is a point frequently examined in the examination of computer skills in public institutions.

Questions of this type often appear in the form of multiple choice questions.

It is important to master the relevant knowledge of the database paradigm.

-------------------------------------------------------------

 

/////////////////////////////////////////////////////////////////////////////

Before interpreting the database paradigm, we must first understand some basic knowledge.

 

Functional Dependency The simple point of functional dependence is that when an attribute set determines another attribute set, it is said that another attribute set depends on the attribute set.

Let R (U) be the relationship mode on the attribute set U, and X and Y are a subset of U:
if the relationship between X and Y is 1: 1 (one-to-one relationship), such as between the school and the principal: 1 relationship, there is a function dependence X → Y and Y → X.
If there is a 1: n relationship between X and Y (one-to-many relationship), if there is a 1: n relationship between age and name, then there is a functional dependency Y → X.
If there is an m: n relationship (many-to-many relationship) between X and Y, such as an m: n relationship between students and courses, then there is no functional dependency between X and Y.

 

Full functional dependency: In a relationship, if a non-primary attribute data item depends on all keywords, it is called full functional dependency.
Example: In the relationship of the grade table (student number, course number, grade), the
complete functional dependence: (student number, course number) → grade, student number-\ → grade, course number-\ → grade, so (student number, course No.) → The score is completely functionally dependent

 

Candidate code / candidate key: if the value of a certain group of attributes in the relationship can uniquely identify a tuple, and its subset cannot, then the attribute group is called a candidate code / candidate key; the
main code: if there is more than one relationship Candidate codes, one of them is selected as the main code;
main attributes && non-main attributes: all attributes of the candidate codes are called main attributes, and attributes not included in any candidate code are called non-main attributes;

 

/////////////////////////////////////////////////////////////////////////////

 

1NF
       
meets the minimum requirements is called the first normal form.
Speaking of people: the first normal form (1NF) means that each column of the database table is an indivisible basic data item, and there cannot be multiple values ​​in the same column, that is, an attribute in the entity cannot have multiple values ​​or cannot have Duplicate attributes.

 

2NF
     
If R belongs to the first normal form, and each non-primary attribute complete function depends on any candidate code, then R belongs to 2NF

To speak people: the second normal form (2NF) is established on the basis of the first normal form (1NF), that is, to meet the second normal form (2NF) must first meet the first normal form (1NF).

The second normal form (2NF) requires that each instance or row in a database table must be uniquely distinguishable.
The second normal form (2NF) requires that the attributes of an entity depend entirely on the primary key. The so-called complete dependence means that there cannot be an attribute that only depends 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. relationship.


3NF
   
If each non-primary attribute in R neither passes code dependence, nor depends partly on code, then R belongs to the third normal form and
speaks: the third normal form (3NF) requires that a database table does not contain any Non-primary key information already included in the table.

For example, there is a department information table, in which each department has information such as department number (dept_id), department name, and department profile. Then, after the department number is listed in the employee information table, department-related information such as department name, department profile, etc. can no longer be added to the employee information table. If there is no department information table, it should be constructed according to the third normal form (3NF), otherwise there will be a lot of data redundancy. In short, the third normal form is that the attribute does not depend on other non-primary attributes.  

 


All non-primary attributes of BCNF are fully functionally dependent on each candidate code;
all primary attributes are also fully functionally dependent on each candidate code that does not contain it;
no attribute is completely dependent on any set of attributes of non-candidate codes .

Example 1: In the relationship model STJ (S, T, J), S represents a student, T represents a teacher, and J represents a course. Each teacher only teaches one course. There are several teachers in each course, and a certain teacher selects a course, which corresponds to a fixed teacher. The following functional dependencies can be obtained from the semantics:
(S, J)-> T; (S, T)-> J; T-> J.
(S, J), (S, T) are all candidate keys.
STJ is 3NF because there are no non-primary attributes that depend on key transfer or partial dependency. But STJ is not a BCNF relationship, because T is the determining factor and T is not a super bond.
Example 2: Assume that the warehouse management relationship table is StorehouseManage (warehouse ID, storage item ID, administrator ID, quantity), and there is an administrator working in only one warehouse; a warehouse can store multiple items. The following determination relationships exist in this database table:
(warehouse ID, storage item ID) → (administrator ID, quantity) (administrator ID, storage item ID) → (warehouse ID, quantity)
Therefore, (warehouse ID, storage item ID) ) And (administrator ID, storage item ID) are candidate keywords for StorehouseManage. The only non-key field in the table is quantity, which is in accordance with the third normal form. However, because there is the following decision relationship:
(warehouse ID) → (administrator ID) (administrator ID) → (warehouse ID)
, that is, there are cases where key fields determine key fields, so it does not conform to the BCNF paradigm.

 

If you, the programmers, are tired of 996 and want to take a test in a public institution, but you do n’t know where to start, you ca n’t find the test preparation information, just ask me to consult, and I ’ve been on the shore for many years. , Has several written and interview experience.

↓↓↓↓↓↓ My WeChat ↓↓↓↓↓↓

 

Guess you like

Origin www.cnblogs.com/kingsgao/p/12721422.html