SqlServer database three paradigm table design standards

1 Overview

   一般地,在进行数据库设计时,应遵循三大原则,也就是我们通常说的三大范式,即第一范式要求确保表中每列的原子性,也就是不可拆分;第二范式要求确保表中每列与主键相关,而不能只与主键的某部分相关(主要针对联合主键),主键列与非主键列遵循完全函数依赖关系,也就是完全依赖;第三范式确保主键列之间没有传递函数依赖关系,也就是消除传递依赖。
  本文将基于三大范式原则,结合具体的实例做简要分析,难度系数:基础。

2 First Normal Form

2.1 Introduction of Examples
Two data tables are designed according to the following scenarios. Please analyze the rationality of the two data tables.

1 Question: Description of requirements: An entity table is needed in the database system to store user information. The attribute "address" requires the province, city and detailed address to be queried.
2
3 Specific examples:
4 Name: Zhang Hongxin; Gender: Male; Age: 26 years old; Phone: 0378-23459876; Province: Henan Province; City: Kaifeng; Detailed address: No. 23 Xinhua Road, Chaoyang District;
5 Name: Wang Yan ; Gender: Female; Age: 25; Tel: 021-2348768; Province: Guizhou Province; City: Guiyang City; Address: No. 6, Shifeng Road, Nanming District, Nanming District;
6 Name: Wang Mei; Gender: Female; Age: 21 years old; Tel: 0571-3876450; Province: Zhejiang Province; City: Hangzhou; Detailed address: No. 352, Binkang Road, Binjiang District;

The first table design
Insert picture description here
The second table design
Insert picture description here
2.2 Analysis The
first table design does not meet the first normal form, why not meet the first normal form? Because the region column is not atomic, it can be split into provinces, cities and specific addresses;

3 Second Normal Form

3.1 Introduction of examples
Two data tables are designed according to the following scenarios. Please analyze the rationality of the two data tables.

1 Requirement description: Design an order information table, the order has multiple products, and the order number and product number are used as the combined primary key.

The first table design
Insert picture description here
The second table design
Insert picture description here
3.2 Analysis The
first table design does not meet the second paradigm, the order number and product number are used as the combined primary key, because the product name, unit, and price columns are only related to the product number, and the order The number has nothing to do with the primary key (joint primary key), which violates the second principle of the paradigm; the
second table design meets the second paradigm, the first design table is split, the product information is separated into another table, and the order is The project table is also separated into another table.

4 Third Normal Form

4.1 Introduction of examples
Two data tables are designed according to the following scenarios. Please analyze the rationality of the two data tables.

1 The following information needs to be stored in the database:
2 Student number; student card number; user ID number; operator level; operation date; operation time;

The first table design
Insert picture description here
The second table design
Insert picture description here
Insert picture description here
4.2 Analysis The
first table design does not meet the third normal form, in the table, a UserID can determine a UserLevel. In this way, UserID depends on StudentNo and CardNo, and UserLevel depends on UserID, which leads to transitive dependence. 3NF is to eliminate this dependence.
The second table design satisfies the third normal form, and the first table is split into two tables.
Reprint address: https://www.cnblogs.com/wangjiming/p/6123066.html

Guess you like

Origin blog.csdn.net/hello_mr_anan/article/details/84024552