传递依赖有什么问题? [英] What is wrong with a transitive dependency?
问题描述
我在我的数据库设计中有一些传递依赖。我被上司告诉这些可能会导致错误。我发现很难找到资源,将告诉我如何有这些依赖将导致错误。他们会导致什么样的问题?
I have some transitive dependencies in my database design. I have been told by my superiors that these can cause bugs. I am finding it difficult to find resources that will tell me how having these dependencies will cause bugs. What kind of problems will they cause?
我不是在争论这个事实,只是渴望了解他们可能导致什么样的问题。
I am not disputing the fact, just eager to learn what kind of problems they can cause.
感谢。
编辑更多详细信息:
来自wikipedia:
From wikipedia :
传递依赖关系
传递依赖关系是一种间接函数依赖关系,其中X→Z仅凭借X→Y和Y→Z。
Transitive dependency A transitive dependency is an indirect functional dependency, one in which X→Z only by virtue of X→Y and Y→Z.
推荐答案
我将通过一个示例解释:
I'll explain by an example:
-------------------------------------------------------------------
| Course | Field | Instructor | Instructor Phone |
-------------------------------------------------------------------
| English | Languages | John Doe | 0123456789 |
| French | Languages | John Doe | 0123456789 |
| Drawing | Art | Alan Smith | 9856321158 |
| PHP | Programming | Camella Ford | 2225558887 |
| C++ | Programming | Camella Ford | 2225558887 |
-------------------------------------------------------------------
- 如果您有
课程
,您可以轻松地获得教师
,课程 - >教师
。 - 如果您有
教师
c $>
- 如果您有
教师
您可以轻松取得电话
,Instructor->电话
。 - If you have a
Course
you can easily get itsInstructor
soCourse ->Instructor
. - If you have an
Instructor
you can't get itsCourse
as he might be teaching different courses. - If you have an
Instructor
you can easily get hisPhone
soInstructor->Phone
. - 如果您同时删除
法语
和code>课程,那么你将删除他们的教师
John Doe
,他的电话号码将永远丢失。 - 无法向您的数据库添加新的
教师
,除非您先为他添加课程
,或者您可以复制 c $>教师中的数据更糟。
- 如果教师
John Doe
更改他的电话号码,那么你将不得不更新他教授的所有课程与新的信息,这很容易犯错误。 - 您不能从数据库中删除教师
- 如果您决定保留教师的出生日期,该怎么办?如果您删除了所有课程,或者将所有课程设置为空。您必须在
Courses
表中添加生日
字段。这是否听起来合乎逻辑?为什么要在课程表中保留教师信息。 - If you delete both the
French
andEnglish
courses then you will delete their instructorJohn Doe
as well and his phone number will be lost forever. - There is no way to add a new
Instructor
to your database unless you add aCourse
for him first, or you can duplicate the data in anInstructors table
which is even worse. - If Instructor
John Doe
changes his phone number then you will have to update all Courses that he teaches with the new info which can be very prone to mistakes. - You can't delete an Instructor from your database unless you delete all the courses he teaches or set all his fields to null.
- What if you decide to keep the birth date of your instructors? You will have to add a
Birth Date
field to theCourses
table. Does this even sound logical? Why keep an instructor information in the courses table in the first place.
这意味着如果你有一个课程
,那么你可以得到教师电话
这意味着课程 - >教师电话
(即传递依赖)
That means the if you have a Course
then you can get the Instructor Phone
which means Course ->Instructor Phone
(i.e. Transitive dependency)
/ p>
Now for the problems:
这篇关于传递依赖有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!