当前位置:网站首页>[three paradigms of database] you can understand it at a glance
[three paradigms of database] you can understand it at a glance
2022-07-06 13:53:00 【No baldness】
Three paradigms
First normal form (1NF)
Make sure the database The atomicity of a field ( That is, indivisibility );
* example : Judge whether the following table conforms to First normal form ?
| Number | full name | Telephone |
| 1 | Xue Baochai | 10076 |
| 2 | Jia Baoyu | 10086 |
| 3 | Lin daiyu | 10096 |
First of all, we need to Business needs To judge Atomic properties of fields , The only thing that can be split in the above table is the name , If the business thinks that the name is a field , Then the table satisfies the first normal form ; But if the business requires our name to be written in two fields ( Last name and first name ), It does not satisfy the first paradigm , Split the name to meet ( Here's the picture ).
| Number | surname | name | Telephone |
| 1 | Xue | Bao Chai | 10076 |
| 2 | Jia | The treasure jade | 10086 |
| 3 | Lin | Daiyu | 10096 |
Second normal form (2NF)
In the meet 1NF On the basis of , It also contains two contents :
(1) The watch must have A primary key
(2) Non primary key columns must Completely dependent on Primary key , You can't rely on only part of the primary key ( Not partially dependent );
* example : Judge whether the following table conforms to Second normal form ?( Set up : The business requirements of this table meet the first paradigm )
| full name | Gender | Telephone | Department name | Department floor |
| Xue Baochai | Woman | 10076 | Public relations | 5 layer |
| Jia Baoyu | male | 10086 | Publicity Department | 3 layer |
| Lin daiyu | Woman | 10096 | Public relations | 5 layer |
First, on the basis of the first paradigm , We can see that the primary key of this table is Composite primary key .( full name + Department name ), Content satisfied (1) The watch must have A primary key
secondly , We found that non primary key columns are partially dependent on primary keys Instead of relying entirely on primary keys : Gender of non primary key column 、 The phone depends on the name , The non primary key column Department floor depends on the Department name
Not satisfied with the content (2) Non primary key columns must Completely dependent on Primary key , You can't rely on only part of the primary key
In order to conform to the second paradigm , We will proceed with the table Split and optimize
| Job number | full name | Gender | Telephone |
| 101 | Xue Baochai | Woman | 10076 |
| 102 | Jia Baoyu | male | 10086 |
| 103 | Lin daiyu | Woman | 10096 |
| Department number | Department name | Department floor |
| 1 | Public relations | 5 layer |
| 2 | Publicity Department | 3 layer |
| 1 | Public relations | 5 layer |
| Department number | Job number | full name | Gender | Telephone |
| 1 | 101 | Xue Baochai | Woman | 10076 |
| 2 | 102 | Jia Baoyu | male | 10086 |
| 1 | 103 | Lin daiyu | Woman | 10096 |
We put Set the department number as the primary key of the Department table ( The foreign key of the master table )、 The job number is set as the primary key of the master table , Because they have no practical business significance , So when we modify the data ( For example, change your name 、 Department name ), You don't have to change it line by line .
Third normal form (3NF)
In the meet 2NF On the basis of , In addition, non primary key columns must Directly dependent on Primary key ( Cannot rely on non primary keys ), There can be no delivery dependency ,
That is, it cannot exist A Depend on B,B Depend on C;
( among A、B Is a non primary key column ,C Primary key )
* example : Judge whether the following table conforms to Third normal form ?( The business requirements of this table have met the second paradigm )
| Department number | Job number | full name | Gender | Telephone | Position | Wages |
| 1 | 101 | Xue Baochai | Woman | 10076 | formal | 8000 |
| 2 | 102 | Jia Baoyu | male | 10086 | Internship | 4000 |
| 1 | 103 | Lin daiyu | Woman | 10096 | formal | 8000 |
In order to conform to the third paradigm , We will proceed with the table Split and optimize
First, on the basis of the first paradigm , We can see that the salary in the non primary key column of the table depends on the position in the non primary key column , There are transitive dependencies , That is, it does not meet the requirements of the third paradigm
| Job number | full name | Gender | Telephone |
| 101 | Xue Baochai | Woman | 10076 |
| 102 | Jia Baoyu | male | 10086 |
| 103 | Lin daiyu | Woman | 10096 |
| Department number | Department name | Department floor |
| 1 | Public relations | 5 layer |
| 2 | Publicity Department | 3 layer |
| 1 | Public relations | 5 layer |
| Job number | Position | Wages |
| 01 | formal | 8000 |
| 02 | Internship | 4000 |
| 01 | formal | 8000 |
| Department number | Job number | full name | Gender | Telephone | Job number |
| 1 | 101 | Xue Baochai | Woman | 10076 | 01 |
| 2 | 102 | Jia Baoyu | male | 10086 | 02 |
| 1 | 103 | Lin daiyu | Woman | 10096 | 01 |
For explanation, please refer to the end of the second paradigm
ps: We must start from the business needs ( That's the scene ) Set out to judge whether it conforms to the paradigm
Why learn paradigm ?
When we communicate business needs with customers Or is it To complete a project , We need to design a suitable data model . here , The importance of standardized design is highlighted .
What is the paradigm ?
A paradigm is a collection of relational patterns that conform to a certain level . The construction of database must follow certain rules ( In a relational database , This rule refers to the paradigm )). The relationship in relational database must meet certain requirements , That is to meet different paradigms .
What problems can learning paradigm solve ?
Learning standardized design can solve the following problems :
1. data redundancy
2. Abnormal problems :
Update exception
Insertion exception
Delete exception
边栏推荐
- 重载和重写的区别
- 7-5 走楼梯升级版(PTA程序设计)
- 记一次猫舍由外到内的渗透撞库操作提取-flag
- 实验四 数组
- 甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
- Principles, advantages and disadvantages of two persistence mechanisms RDB and AOF of redis
- 1. First knowledge of C language (1)
- 这次,彻底搞清楚MySQL索引
- 5月14日杂谈
- js判断对象是否是数组的几种方式
猜你喜欢

Matlab opens M file garbled solution

3. Input and output functions (printf, scanf, getchar and putchar)

Leetcode. 3. Longest substring without repeated characters - more than 100% solution

Redis的两种持久化机制RDB和AOF的原理和优缺点

(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。

A piece of music composed by buzzer (Chengdu)

hashCode()与equals()之间的关系

FAQs and answers to the imitation Niuke technology blog project (III)

The latest tank battle 2022 full development notes-1

Cookie和Session的区别
随机推荐
JS several ways to judge whether an object is an array
Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems
SRC mining ideas and methods
String abc = new String(“abc“),到底创建了几个对象
实验六 继承和多态
[graduation season · advanced technology Er] goodbye, my student days
FAQs and answers to the imitation Niuke technology blog project (II)
杂谈0516
9. Pointer (upper)
The difference between overloading and rewriting
使用Spacedesk实现局域网内任意设备作为电脑拓展屏
Mode 1 two-way serial communication is adopted between machine a and machine B, and the specific requirements are as follows: (1) the K1 key of machine a can control the ledi of machine B to turn on a
实验九 输入输出流(节选)
仿牛客技术博客项目常见问题及解答(三)
强化学习基础记录
ABA问题遇到过吗,详细说以下,如何避免ABA问题
Relationship between hashcode() and equals()
7-3 构造散列表(PTA程序设计)
2022泰迪杯数据挖掘挑战赛C题思路及赛后总结
[the Nine Yang Manual] 2017 Fudan University Applied Statistics real problem + analysis