Home > php教程 > php手册 > 数据库三范式,轻松理解

数据库三范式,轻松理解

WBOY
Release: 2016-06-13 10:36:59
Original
1091 people have browsed it

网上搜罗了一大堆关于数据库范式理解的文章,都是千律一篇的复制粘贴,连例子都是一模一样,拜托有点创意好不,实在看不下去,自己写一篇个人理解三范式的文章。如果有理解上的不正确之处,请联系我:279537592#qq.com (#=>@)

官方定义:第一范式(1NF):数据库表中的字段都是单一属性的,不可再分。
我的理解:第一范式这个不用說了,只要是关系数据库都满足第一范式

官方定义:第二范式(2NF):数据库表中不存在非关键字段对任一候选关键字段的部分函数依赖
我的理解:在第二范式中组合主键(AB)【注明:也叫做复合主键】里面的A或者B 与其他字段不能存在组合重复,为解决这个问题,通常的做法是咱们不用组合主键,添加一个ID,做为单一主键即可满足第二范式。如果不想添加ID,请满足组合主键(AB)里面的A或者B 与其他字段不能存在组合重复。
如:不满足第二范式,复合主键中的A与字段C组合重复
+------------+-----------+-------------------+
    pk                pk             row
+------------+-----------+-------------------+
    A                  B                  C
+------------+-----------+-------------------+
    A                  D                  C
+------------+-----------+-------------------+
    A                  E                  C
+------------+-----------+-------------------+

改为这样满足第二范式(但是不满足第三范式,字段A与字段C是组合重复):
+---------+------------+-----------+-------------------+
    pk            row             row             row
+---------+------------+-----------+-------------------+
      1              A               B                  C
+---------+------------+-----------+-------------------+
      2              A               D                  C
+---------+------------+-----------+-------------------+
      3              A               E                  C
+---------+------------+-----------+-------------------+

官方定义:第三范式(3NF):在第二范式的基础上,数据表中如果不存在非关键字段对任一候选关键字段的传递函数依赖则符合第三 范式。
我的理解:在第三范式中字段与字段之间不能存在组合重复
如:不满足第三范式,字段A与字段C组合重复
+---------+------------+-----------+-------------------+---------------+
    pk            row             row             row                        row
+---------+------------+-----------+-------------------+---------------+
      1              A               B                  C                           F
+---------+------------+-----------+-------------------+---------------+
      2              A               D                  C                          G
+---------+------------+-----------+-------------------+---------------+
      3              A               E                  C                           K
+---------+------------+-----------+-------------------+---------------+

改为这样满足第三范式:
表1
+---------+------------+-----------+
    pk            row            row        
+---------+------------+-----------+
      1              A               B              
+---------+------------+-----------+
      2              A               D                
+---------+------------+-----------+
      3              A               E                
+---------+------------+-----------+
和表2
+---------+-------------------+------------+
    pk             row                       row
+---------+-------------------+------------+
      1              C                           F
+---------+--

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template