当前位置:网站首页>Three paradigms of database design

Three paradigms of database design

2022-07-04 08:14:00 Vivien_ oO0

brief introduction

In order to establish less redundancy , A well structured database , Certain rules must be observed when designing the database , In relational databases, this rule is the paradigm . A paradigm is a collection of relational patterns that conform to a certain level . The relationship in relational database must meet certain requirements , That is to meet different paradigms .

At present, there are six paradigms in relational database , Generally speaking, as long as the database meets the third paradigm , And what we often use is what we call the three paradigms , First normal form , Second and third paradigms .

First normal form

Atomicity 、 Indivisibility

What does that mean ?
It requires that every field in your table cannot be further split , Are the smallest data units .

If there is the following student information form

Student information sheet

Student number full name Home address College number The name of the College Dormitory number Dormitory type The number of beds in the dormitory
001 Zhang San Xi'an, Shaanxi Province 100001 College of science 222 standard room 4
002 Li Si Xianyang City, Shaanxi Province 100002 school of computing 333 Non standard room 6
003 Wang Wu Baoji City, Shaanxi Province 100003 School of Marxism 666 standard room 4

The address column can be further split into provinces 、 City So this table does not conform to the first normal form

Second normal form

Second normal form It is required that on the premise of ensuring the first paradigm , requirement Each column should be related to the primary key , It cannot only be related to a part of the primary key , Require entity uniqueness .

For example, the following table :

Student number full name College number The name of the College Dormitory number Dormitory type The number of beds in the dormitory
001 Zhang San 100001 College of science 222 standard room 4
002 Li Si 100002 school of computing 333 Non standard room 6
003 Wang Wu 100003 School of Marxism 666 standard room 4

The primary key is student number, college number and dormitory number
full name 、–> Student number
The name of the College —> College number
Dormitory type 、 The number of beds in the dormitory —> Dormitory number

The above is only partially dependent So it violates the second paradigm So you should split the table

Student number full name College number Dormitory number
001 Zhang San 100001222
002 Li Si 100002333
003 Wang Wu 100003666
College number The name of the College
100001 College of science
100002 school of computing
100003 School of Marxism
Dormitory number Dormitory type The number of beds in the dormitory
222 standard room 4
333 Non standard room 6
666 standard room 4

The primary key of the first table is student number , The primary key of the second table is the college number , The primary key of the table in Chapter 3 is dormitory number

This design makes the database clearer , If you need to find the name of the College , Check directly in the college table

Third normal form

The third paradigm requires Each column is directly related to the primary key column Not indirectly , That is, limit the redundancy of columns

.

Dormitory number Dormitory type The number of beds in the dormitory
222 standard room 4
333 Non standard room 6
666 standard room 4

Like the above table . Dormitory number —> Dormitory type —> The number of beds in the dormitory
From these dependencies, we can choose the dormitory number —> The number of beds in the dormitory
Dormitory No —> The number of beds in the dormitory is called transmission dependence

So the table should be subdivided again

Dormitory number Dormitory type
222 standard room
333 Non standard room
666 standard room
Dormitory type The number of beds in the dormitory
standard room 4
Non standard room 6
standard room 4

In this way, there is no indirect dependency .

Be careful : The repeated occurrence of primary keys and foreign keys in multiple tables does not belong to data redundancy , The repetition of non key fields is data redundancy .

原网站

版权声明
本文为[Vivien_ oO0]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141504070662.html