数据库范式4nf什么意思
In this tutorial we will learn about the 1st(First) Normal Form which is more like the Step 1 of the Normalization process. The 1st Normal form expects you to design your table in such a way that it can easily be extended and it is easier for you to retrieve data from it whenever required.
在本教程中,我们将学习第一(第一)范式,它更像是“归一化”过程的步骤1。 1st Normal表单希望您以易于扩展的方式设计表,并在需要时更轻松地从中检索数据。
In our last tutorial we learned and understood how data redundancy or repetition can lead to several issues like Insertion, Deletion and Updation anomalies and how Normalization can reduce data redundancy and make the data more meaningful.
在上一教程中,我们了解并理解了数据冗余或重复如何导致诸如插入,删除和更新异常之类的若干问题,以及规范化如何减少数据冗余并使数据更有意义。
bad database design. 错误的数据库设计 。
第一个范式的规则 (Rules for First Normal Form)
The first normal form expects you to follow a few simple rules while designing your database, and they are:
第一个范式期望您在设计数据库时遵循一些简单的规则,它们是:
规则1:单值属性 (Rule 1: Single Valued Attributes)
Each column of your table should be single valued which means they should not contain multiple values. We will explain this with help of an example later, let's see the other rules for now.
表的每一列应为单值,这意味着它们不应包含多个值。 我们将在后面的示例中对此进行解释,现在让我们看看其他规则。
规则2:属性域不应更改 (Rule 2: Attribute Domain should not change)
This is more of a "Common Sense" rule. In each column the values stored must be of the same kind or type.
这更多是“常识”规则。 在每一列中,存储的值必须具有相同的种类或类型。
For example: If you have a column dob
to save date of births of a set of people, then you cannot or you must not save 'names' of some of them in that column along with 'date of birth' of others in that column. It should hold only 'date of birth' for all the records/rows.
例如:如果你有一列dob
保存一组人,那么你就不能或者你不能在该列保存的一些人的名字“在该列别人的“出生日期”沿的出生日期。 所有记录/行都应仅保留“出生日期”。
规则3:属性/列的唯一名称 (Rule 3: Unique name for Attributes/Columns)
This rule expects that each column in a table should have a unique name. This is to avoid confusion at the time of retrieving data or performing any other operation on the stored data.
该规则要求表中的每一列都应具有唯一的名称。 这是为了避免在检索数据或对存储的数据执行任何其他操作时造成混乱。
If one or more columns have same name, then the DBMS system will be left confused.
如果一个或多个列具有相同的名称,那么DBMS系统将被混淆。
规则4:顺序无关紧要 (Rule 4: Order doesn't matters)
This rule says that the order in which you store the data in your table doesn't matter.
该规则表明,在表中存储数据的顺序无关紧要。
实例时间 (Time for an Example)
Although all the rules are self explanatory still let's take an example where we will create a table to store student data which will have student's roll no., their name and the name of subjects they have opted for.
尽管所有规则都是不言自明的,但还是让我们以一个示例为例,在该示例中,我们将创建一个表来存储学生数据,其中将包含学生卷名,他们的姓名和他们选择的学科名称。
Here is our table, with some sample data added to it.
这是我们的表,其中添加了一些示例数据。
roll_no | name | subject |
---|---|---|
101 | Akon | OS, CN |
103 | Ckon | Java |
102 | Bkon | C, C++ |
roll_no | 名称 | 学科 |
---|---|---|
101 | 阿Kong | 操作系统,CN |
103 | 康 | Java |
102 | 布Kong | C,C ++ |
Our table already satisfies 3 rules out of the 4 rules, as all our column names are unique, we have stored data in the order we wanted to and we have not inter-mixed different type of data in columns.
我们的表已经满足了4条规则中的3条规则,因为我们所有的列名都是唯一的,我们已经按照想要的顺序存储了数据,并且没有在列中混合使用不同类型的数据。
But out of the 3 different students in our table, 2 have opted for more than 1 subject. And we have stored the subject names in a single column. But as per the 1st Normal form each column must contain atomic value.
但是在我们表中的3名不同的学生中,有2名选择了超过1门科目。 并且我们将主题名称存储在单个列中。 但是按照第一范式的形式,每一列都必须包含原子值。
如何解决这个问题呢? (How to solve this Problem?)
It's very simple, because all we have to do is break the values into atomic values.
这很简单,因为我们要做的就是将这些值分解为原子值。
Here is our updated table and it now satisfies the First Normal Form.
这是我们更新的表格,现在满足第一范式。
roll_no | name | subject |
---|---|---|
101 | Akon | OS |
101 | Akon | CN |
103 | Ckon | Java |
102 | Bkon | C |
102 | Bkon | C++ |
roll_no | 名称 | 学科 |
---|---|---|
101 | 阿Kong | 操作系统 |
101 | 阿Kong | CN |
103 | 康 | Java |
102 | 布Kong | C |
102 | 布Kong | C ++ |
By doing so, although a few values are getting repeated but values for the subject
column are now atomic for each record/row.
这样,尽管一些值被重复,但是对于每个记录/行, subject
列的值现在都是原子的。
Using the First Normal Form, data redundancy increases, as there will be many columns with same data in multiple rows but each row as a whole will be unique.
使用“第一范式”,数据冗余增加,因为在多行中将有许多列具有相同的数据,但整体上每一行都是唯一的。
翻译自: https://www.studytonight.com/dbms/first-normal-form.php
数据库范式4nf什么意思