Database Design - paradigm

First, data normalization

  1, paradigm

    Good database design for data storage performance and post-program development, have an important impact.

    Establish a standardized database will need to meet certain rules to optimize the design and store data, these rules are called paradigm .

    When setting a relational database, to comply with different specifications, design a reasonable relational database, which is referred to different specifications different paradigms, presenting subnormal paradigms, the higher the smaller the redundant database paradigm.

  2, the three major paradigms

    Currently there are six relational database paradigm: First Normal Form (1NF), second normal form (1NF), Third Normal Form (3NF), Bath - Cape Cod Paradigm (BCNF), fourth normal form (4NF) and fifth paradigm ( 5NF, also known as the perfect paradigm).

    Meet the minimum requirements of the paradigm is the first paradigm (1NF). More further satisfies regulatory requirements on the basis of the first paradigm referred to as second paradigm (2NF), and so the remaining paradigm. In general, the value of the database needs to third normal form (3NF) on the line.

Second, the first normal form (1NF)

  1, the concept of

    Each database table columns are indivisible atomic data item, is not a non-atomic set of data items, like arrays.

    That is, when a list of multiple values, must be split into different columns.

    IN A WORD: first paradigm no longer split each column, called atomic.

  2, case

student ID Full name class
1 Joe Smith Three times a year
2 John Doe Year two
3 Wang Wu Two years three shifts

 

Third, a second paradigm (2NF)

  1, the concept of

    The premise of meeting the first paradigm, in the table for each field are entirely dependent on the primary key . (Non-code must be totally dependent on the properties of the code, i.e. non-primary property to eliminate the main part of the function code dependent)

    The so-called completely dependent on the presence of means can not rely solely on a part of the primary key column. In short, the second is based on the first paradigm paradigm on all columns completely dependent on the primary key column.

    When the presence of a compound comprising a plurality of the primary key columns of the primary key, the case does not meet the second paradigm will occur.

    For example: There is a primary key of the table has two columns, there is not a mathematical, it relies only on one of the column, this time do not meet the second paradigm.

  2, general concepts

    ① functional dependency : A -> B value, if (attribute group) A property values, property B can be determined uniquely. Called B relies on A. For example: Student ID -> Name

    ② fully functional dependency : A - determining> B, if A is a group attribute, the attribute value B need to rely on all attribute values A set of attributes. For example :( student number, course name) -> Score

    ③ Part functional dependency : A -> B, if A is a group attribute, the attribute value of B is determined only dependent on the value of some of the attribute A can be set. For example :( student number, course name) -> Name

    ④ transfer function dependent :. A -> B, B -> C If (group attribute) of the attribute values A, B uniquely determine the value of the property, the value may be determined by the attribute B (attribute group) only C value of the property, called transfer function depends on C A. For example: Student ID -> department name, department name -> Department.

    ⑤ code : if in a table, an attribute or group, are totally dependent on all other attributes, the called code attribute (group) for the table.

      •  Main properties: Code set of attributes for all attributes
      •    Non-live properties: Property Code attribute groups through addition

  3 features

    ① a table describe only one thing

    ② Each column of the table are entirely dependent on the primary key

  4, case

    ① library card table

Student identification card Student ID Name Student card processing time Library card number Library card name Library card processing time

    ② divided into two tables

Student identification card Student ID Name Student card processing time
Library card number Library card name Library card processing time

Fourth, Third Normal Form (3NF)

  1, the concept of

     Under the premise to meet the second paradigm, each column of the table are directly dependent on the primary key , rather than indirectly through other columns dependent on the primary key (2NF eliminate the dependency on the basis of transmission).

     简而言之,第三范式就是所有列不依赖于其它非主键列,就是在满足第二范式的基础上,任何非主列不得传递依赖于主键。

     所谓传递依赖,指的是如果存在“A—>B—>C”的决定关系,则 C 传递依赖于 A。因为,满足第三范式的数据库表不应该存在依赖关系。

  2、案例

    学生信息表

学号 姓名 年龄 所在学院 学院地点

     存在传递的决定关系:

      学号 —> 所在学院 —> 学院地点

    拆分为两张表

学号 姓名 年龄 所在学院的编号(外键)

 

学院编号 所在学院 学院地点

 

五、三大范式小结

范式 特点
1NF 原子性:表中每列不可再拆分。
2NF 不产生局部依赖,一张表只描述一件事情
3NF 不产生传递依赖,表中每一列都直接依赖于主键。而不是通过其它列间接依赖于主键。

Guess you like

Origin www.cnblogs.com/niujifei/p/11586650.html