简体   繁体   English

分解为BCNF

[英]Decomposition to BCNF

While I do understand what the normal forms are, I have trouble working with them. 虽然我确实了解正常形式是什么,但在使用它们时遇到了麻烦。 I am following a course in database systems and somehow I am a bit lost on this. 我正在学习数据库系统的课程,因此在某种程度上我迷失了方向。 I have tried Google, stackoverflow, slides of the course and the book, but examples seem to throw me off track every time. 我尝试过Google,stackoverflow,课程幻灯片和书籍,但是每次出现的示例似乎都使我偏离了轨道。 I would very much like some pointers if I make some wrong assumptions/conclusions along this post, but also some pointers as to what I am missing in the end. 如果我在这篇文章中做出一些错误的假设/结论,我将非常希望获得一些指导,但最后我还是会缺少一些指导。

A specific exercise I ran into today was this: Given this DB, convert it to BCNF: 我今天参加的一个具体练习是:给定此数据库,将其转换为BCNF:

DB:  
AB -> EF  
F -> AB  
A -> CD

As I understand it there are two possible candidate keys here. 据我了解,这里有两个可能的候选键。 AB and F. This is because both are able to derive the entire DB, and because both are minimal in the sense that they consist of a single left hand side. AB和F。这是因为两者都可以派生整个DB,并且在它们都由一个左侧组成的意义上来说两者都是最小的。

Let's say we go with F as the primary key. 假设我们将F作为主键。
Originally: DB(F->AB) 最初: DB(F->AB)

For 1NF there seems to be no repeating groups. 对于1NF,似乎没有重复的基团。 Check. 校验。
For 2NF there seems to be no partial dependencies. 对于2NF,似乎没有部分依赖性。 (Would this not be impossible with F being the only primary key?) (用F作为唯一主键,这不是不可能吗?)
For 3NF there's a problem! 对于3NF,有一个问题! Both AB and A are not keys but determines other attributes. AB和A都不是键,而是确定其他属性。 To solve this, they need to become keys: (Sorry for the lack of underlining, seems there is no option to underline) 为了解决这个问题,他们需要成为关键:(很抱歉,没有下划线,似乎没有选择下划线的选项)

DB(F->AB)
R1(AB->EF)
R2(A->CD)

As I understand it, for BCNF, the procedure goes like this: Compare the 3NF DB with the original DB. 据我了解,对于BCNF,该过程如下:将3NF DB与原始DB进行比较。 Find occurences in the original DB where the entire left hand side is present the 3NF DB and at least one right hand side is present. 查找原始DB中出现的整个3NF DB,至少存在一个右侧的情况。 I am not quite sure how it is ever possible to not have this. 我不太确定怎么可能没有这个。 Maybe i misunderstood this part. 也许我误会了这部分。 Anyways, continuing; 无论如何,继续;

First occurrence is F->AB. 第一次出现是F-> AB。 This is the primary key and is thus OK. 这是主键,因此可以。
Second occurence is AB->EF. 第二次出现是AB-> EF。 Since AB is a candidate key, this is OK as well. 由于AB是候选键,因此也可以。
Last occurence is A->CD. 最后一次出现是A-> CD。 A is only part of a candidate key. A只是候选密钥的一部分。 This violates BCNF and must be rewritten. 这违反了BCNF,必须重写。 And this is where I get off the train completely. 这就是我完全下车的地方。 I have no idea how to rewrite this, and I am not sure if the procedure so far makes sense. 我不知道如何重写它,并且我不确定到目前为止该程序是否有意义。 Could anyone help me wrap it up? 谁能帮我把它包好吗?

You're right: A->CD is the dependency which violates BCNF. 您是对的:A-> CD是违反BCNF的依赖项。 You split your relation in two: 您将关系分为两部分:

  • attributes from the violating dependecy: ACD 违反依赖性的属性:ACD
  • attributes from the right side of the violating dependency (A) together with the remaining attributes: thus you get ABEF 违反依赖项(A)右侧的属性以及其余属性:这样就得到ABEF

This is where you stop as all functional dependencies conform to BCND rules. 因为所有功能依赖项均符合BCND规则,所以在这里停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM