Normal Form is a set that with a particular level. (范式是符合某一种级别的关系模式的集合。)
Create database must follow certain rules. In the relational database, this rule is the Normal Form.
Database that meet these Normal Form are concise and clear stuctured. At the same time, there are no exceptions when insert, delete and update.
Generally, the Relationship is divided into 5 Normal Form.
1NF, 2NF, 3NF, Boyce-Codd NF, 4NF, 5NF.
In generally, the database only to meet the 3NF.
1NF
In any relational database, the 1NF is the basic requirement.
If the database that does not meet the 1NF, it isn't a relational database.
The 1NF is a non repeating column.
* There must have primary key.
* Primary key cannot be empty.
* The Primary Key can't be repeated
* the column can't be divided.
StudentNo |
Name |
Sex |
Email |
Phone |
001 |
LaoTao |
Mail |
laotao@m.com |
18866688688 |
2NF
Meeting the 2NF must meeting the 1NF.
Each non key attribute is not part dependent on the Primary Key attribute.
So the main task of the 2NF is to meet the 1NF, and eliminate some dependence of the function.
StudentNo |
Name |
Sex |
Email |
Phone |
ClassNo |
classAddress |
001 |
LaoTao |
Mail |
lt@m.cn |
18866688688 |
1003 |
67#A205 |
This table is fully satisfied with the 1NF.
The primary key is consisting of the "StudentNo" and "ClassNO".
But the "ClassAddress" depends on the key(ClassNo -> ClassAddress), so it must be divided into two tables.
Table 1
StudentNo |
Name |
Sex |
Email |
Phone |
ClassNo |
001 |
LaoTao |
Mail |
lt@m.cn |
18866688688 |
1003 |
Table 2
ClassNO |
ClassAddress |
1003 |
67#205 |
3NF
如果关系模型R是第二范式, 且没有一个非键属性传递依赖于键,则称R是3NF.
The 3NF requires a database table does not contain the non primary key information that has benn included in other tables.
StudentNo |
Name |
Sex |
Email |
bounsLevel |
bouns |
001 |
LaoTao |
Mail |
lt@m.cn |
Good |
£1000 |
This table is fully satisfied with the 2NF.But boundsLevel and bounds has a transitive dependency(传递依赖).
StudentNo |
Name |
Sex |
Email |
boundsNo |
001 |
LaoTao |
Mail |
lt@m.cn |
01 |
boundsNo |
bounsLevel |
bouns |
01 |
Good |
£1000 |
I'd love using the boundsNo as the Primary Key,
There are two reasons:
* 1)don't use the characters as Primary Key.
* 2)Generally, use the unrelated key in preference as the primary Key.
BCNF
Boyce-Codd Normal Formal
三层模式模型
E-R图