数据库中的规范化 [英] normalization in database

查看:41
本文介绍了数据库中的规范化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子.我怎样才能正常化这个.

I have one table. How can I normalize this.

推荐答案

鉴于您的数据集,这是个好问题.请记住,标准化的全部意义在于减少重复.3NF 通常是最好的方法.但是根据我的经验,我发现如果重复值将是该表中的唯一值,那么将其提取到另一个表中非常没有什么好处.以重复次数最多的列 emp_type 为例.如果您要将其规范化为一个单独的表,它将如下所示:

Good question given your data set. Keep in mind the whole point of normalization is to reduce duplication. 3NF is often the best way to go. But given my experience I've found very little benefit to pulling a repeated value out into a different table if it will be the only value in that table. Take for example your most duplicated column, emp_type. If you were to normalize it into a separate table , it would look like this:

Emp_Type_Id | Emp_type
------------------------
1           | Manager
2           | Engineer
3           | Tech Support

您当前的表格将如下所示:

And your current table would look like:

Emp_ID | Emp_Name | Salary | Emp_Type_Id | Emp_Skill
----------------------------------------------------
1      | raj      | 90000  | 1           | Department
2      | ravi     | 50000  | 2           | Software
3      | shyam    | 70000  | 2           | Hardware
.
.
.

这在技术上比以前更加规范化,因为 emp_type 值不再在您的数据库中重复.但是处理单独的表和单个值的关系要麻烦得多.如果 emp_type 还包括其他信息,例如 Valid_Salary_Range、Department_Location 等,那么最好将其标准化为单独的表.但是,如果它只是您要标准化的单个值,那么存储该值与存储指向该值的 ID 之间有什么区别?在我看来,这是一个毫无意义的额外步骤.

This is technically more normalized than before as the emp_type value is no longer repeated in your database. But it's significantly more hassle to deal with a separate table and a relationship for a single value. If emp_type included other information as well such as Valid_Salary_Range, Department_Location, etc. then it would absolutely be best to normalize it out into a separate table. But if it's only a single value you are normalizing, what's the difference between storing the value as opposed to storing an ID pointed to that value? In my opinion it's a pointless extra step.

长话短说,我根本不会标准化你的表格,它已经标准化到足够的水平.

Long story short, I would not normalize your table at all, it's already normalized to a sufficient level.

这篇关于数据库中的规范化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆