来自函数依赖的候选键

发布于 2024-08-30 08:21:19 字数 100 浏览 12 评论 0原文

给定具有属性 ABCDE 的关系 R。您将获得以下依赖项:A -> B,BC -> E、ED->答:我已经有了答案,CDE、ACD、BCD。我只需要知道该怎么做。谢谢。

Given the Relation R with attributes ABCDE. You are given the following dependencies: A -> B, BC -> E, and ED -> A. I already have the answer which is CDE, ACD, and BCD. I just need to know how to do it. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

‘画卷フ 2024-09-06 08:21:19

候选键是最小超级键。换句话说,密钥中没有多余的属性。查找候选键的第一步是查找所有超级键。对于那些不熟悉的人来说,超级键是一组属性,其闭包是所有属性的集合。换句话说,超级键是一组可以开始的属性,遵循函数依赖关系,将引导您找到包含每个属性的集合。

由于我们有函数依赖关系:A -> B,BC -> E、ED-> A,我们有以下超级键:

  • ABCDE(所有属性始终是一个超级键)
  • BCED(我们可以通过 ED -> A 获得属性 A)
  • ACDE(只需通过 A -> B 添加 B)
  • ABCD(只需通过 A -> B 添加 E ) BC -> E)
  • ACD (通过 A -> B 得到 B,再通过 BC -> E 得到 E)
  • BCD (通过 BC -> E 得到 E,再由 ED 得到 A -> A)
  • CDE(我们可以通过 ED -> A 得到 A,然后从 A -> B 得到 B)

(这里要实现的一个技巧是,因为 C 和 D 永远不会出现在函数依赖的右侧) ,每个键必须同时包含 C 和 D)

现在我们有了所有超级键,我们可以看到只有最后三个是候选键。因为前四个都可以被修剪掉。但是我们不能从最后三个超级键中删除任何属性,同时仍然让它们仍然是超级键。

因此候选键是:ACD、BCD 和 CDE。

A candidate key is a minimal superkey. In other words, there are no superflous attributes in the key. The first step to finding a candidate key, is to find all the superkeys. For those unfamiliar, a super key is a set of attributes whose closure is the set of all atributes. In other words, a super key is a set of attributes you can start from, and following functional dependencies, will lead you to a set containing each and every attribute.

Since we have the functional dependencies: A -> B, BC -> E, and ED -> A, we have the following superkeys:

  • ABCDE (All attributes is always a super key)
  • BCED (We can get attribute A through ED -> A)
  • ACDE (Just add B through A -> B)
  • ABCD (Just add E through BC -> E)
  • ACD (We can get B through A -> B, and then we can get E through BC -> E)
  • BCD (We can get E through BC -> E, and then A from ED -> A)
  • CDE (We can get A through ED -> A and then B from A -> B)

(One trick here to realize, is that since C and D never appear on the right side of a functional dependency, every key must include both C and D)

Now that we have all our super keys, we can see that only the last three are candidate keys. Since the first four can all be trimmed down. But we cannot take any attributes away from the last three superkeys and still have them remain a superkey.

Thus the candidate keys are: ACD, BCD, and CDE.

ˇ宁静的妩媚 2024-09-06 08:21:19

要找到候选键,您需要将 FD 拆分为左、中、右属性
- 左侧包括仅显示在左侧(CD)的属性
- 中间包括显示在左侧和右侧的属性 (ABE)
- 右侧包括仅出现在右侧的属性(无)

现在从左侧找到属性的闭包:
* CD+->光盘
由于我们没有获得关系的所有属性,因此我们需要一次添加一个中间属性 (ABE),并尝试再次找到闭包。

所以:
* CDA+-> CDABE(CDA是候选键)
* CDB+-> CDBEA(CDB是候选键)
* CDE+-> CDEAB(CDE是候选键)

To find the candidate key you need to split the FD's into attributes into Left, Middle, Right
- The Left includes attributes that only show up in the left hand side (CD)
- The Middle includes attributes that show up in both left and right (ABE)
- The Right includes attribues that only show up in the right hand side (none)

Now find the closure of attributes from the Left:
* CD+ -> CD
Since we do not get all the attributes of the relation we need to add the Middle attributes (ABE) one at a time and try to find the closure again.

So:
* CDA+ -> CDABE (CDA is a candidate key)
* CDB+ -> CDBEA (CDB is a candidate key)
* CDE+ -> CDEAB (CDE is a candidate key)

我很坚强 2024-09-06 08:21:19

使用算法;

1.采用任何属性或属性集

,例如:ACD

2.采用第一个提到的函数依赖性

,例如:A -> A B

3. 依赖项的 LHS 是您在步骤 1 中选择的属性的子集吗?

如果是,则将功能依赖项的 RHS 添加到属性中。
如果不是,请忽略此功能依赖性。

例如:A是ACD的子集。所以将B添加到ACD中。 ACD 现在是 ABCD

4。现在转到下一个函数依赖性。重复步骤 3。

例如:BC ->乙
BC是ABCD的子集。所以ABCD现在是ABCDE

5。如果你现在拥有所有属性,你可以停止。

如果您没有所有属性,请继续执行下一个函数依赖项并重复步骤 3。如果您已到达最后一个函数依赖项并且没有所有属性,请返回到第一个函数依赖项并重复步骤 3 和 4继续在此循环中循环,直到无论您重复步骤 3 的函数依赖性如何,您所拥有的属性集都不会更改。

例如:由于我有属性集 ACD 的 ABCDE,所以我可以停止。

如果你拥有所有属性,那么你就有了一个超级键。
例如:ACD 是一个超级键,因为我有 ABCDE。

Use an algorithm;

1.Take any attribute or set of attributes

eg: ACD

2.Take the first mentioned functional dependency

eg: A -> B

3.Is the L.H.S of the dependency a subset of the attribute/s you chose in step 1?

If yes add the R.H.S of the functional dependency to the attribute.
If no,ignore this functional dependency.

eg: A is a subset of ACD. So add B to ACD. ACD is now ABCD

4.Now go to the next functional dependency.Repeat step 3.

eg: BC -> E
BC is a subset of ABCD. So ABCD is now ABCDE

5.If you have all the attributes now, you can stop.

If you don't have all the attributes, keep going to the next functional dependency and repeat step 3. If you have reached the last functional dependency and do not have all attributes, go back to the first functional dependency and repeat steps 3 and 4. Keep cycling in this loop until the set of attributes you have don't change no matter the functional dependency you repeat step 3 with.

eg: As I have ABCDE for attribute set ACD, I can stop.

If you have all attributes you have a superkey.
eg: ACD is a superkey because I have ABCDE.

小情绪 2024-09-06 08:21:19

CD是候选键,所以ACD、BCD、CDE都可以是候选键。 C、D 不会出现在任何函数依赖关系的右侧,这就是为什么 CD 是候选键。

将帮助您理解。

CD is the candidate key, so ACD, BCD, CDE all can be candidate key. C,D do not appear in the right side of any functional dependencies which is why CD is candidate key.

This will help you to understand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文