简体   繁体   English

2NF和3NF标准化

[英]2NF and 3NF Normalization

I seem to have a strange problem when doing normalization problems. 在进行规范化问题时,我似乎有一个奇怪的问题。 When I'm giving relations with actual names I can figure these out easily but when I'm given letters it seems to be a lot harder. 当我提供与真实姓名的关系时,我可以很容易地弄清楚这些,但是当我得到字母时,这似乎要困难得多。

For the following problem I don't know why it's not 3NF and why it is 2NF. 对于以下问题,我不知道为什么不是3NF以及为什么是2NF。

Given R (A, B, C, D, E, F) 给定R(A,B,C,D,E,F)

FDs = {AB->C, DBE->A, BC->D, BE->F, F->D} FD = {AB-> C,DBE-> A,BC-> D,BE-> F,F-> D}

So for 2NF all the right hand side attributes must be fully functionally dependent on the left hand side attributes. 因此,对于2NF,所有右侧属性必须在功能上完全取决于左侧属性。 For 3NF either all the left hand side attributes must be superkeys or the right hand attributes must be prime attributes. 对于3NF,要么所有左侧属性都必须是超键,要么右侧属性必须是素数属性。

I tried drawing this out, but I can't even find a candidate key. 我尝试将其绘制出来,但是我什至找不到候选密钥。 Can anyone help me determine why this is not 3NF? 谁能帮我确定为什么不是3NF? Also, what is the candidate key here? 另外,这里的候选密钥是什么? Since I don't see any attribute that has a closure equal to the original relation. 由于我看不到具有等于原始关系的闭包的任何属性。

I seem to have a strange problem when doing normalization problems. 在进行规范化问题时,我似乎有一个奇怪的问题。 When I'm giving relations with actual names I can figure these out easily but when I'm given letters it seems to be a lot harder. 当我提供与真实姓名的关系时,我可以很容易地弄清楚这些,但是当我得到字母时,这似乎要困难得多。

Yes, its less intuitive with letters. 是的,它的字母不那么直观。 I will tell you a neat method which you can follow to determine the candidate keys in such situations : 我将告诉您一种简洁的方法,在这种情况下,您可以按照该方法确定候选关键字:

Make three columns left( L ), middle( M ) and right( R ) where left columns consists of all the attributes that appear only on the left side in all the given functional dependencies. 使三个列分别为left( L ),middle( M )和right( R ),其中左列包含所有在所有给定功能依赖项中仅出现在左侧的属性。 In our case such attributes will be B and E since they are always on the left side of any FD given (or you can say they are never on the right side in any of the given FD.). 在我们的情况下,此类属性将为BE因为它们始终位于给定FD的左侧(或者您可以说它们从未位于给定FD的右侧)。 Similarly middle column contains attribute that appear on both left and right side of the given FD's. 类似地,中间列包含出现在给定FD的左侧和右侧的属性。 So we have A , C , D and F in the middle column. 因此,在中间列中有ACDF The right column contains attributes which only occur on the right hand side of FD's (never on the LHS of any given FD's). 右列包含的属性仅出现在FD的右侧(从不出现在任何给定FD的LHS上)。 So we have : 因此,我们有:

L  |   M   |R
B,E|A,C,D,F|-

Now that you have this table remember the following rules: ( these are very intuitive ) 现在您有了此表,请记住以下规则:( 这些非常直观

  • Attributes in the left( L ) column are always part of the candidate keys left( L )列中的属性始终是候选键的一部分
  • Attributes in the right( R ) column are never part of the candidate keys right( R )列中的属性永远不会成为候选键的一部分
  • Attributes in the middle( M ) column may or may not be a part of the candidate keys. middle( M )列中的属性可以或可以不是候选关键字的一部分。

So in our case we start with checking if BE is a candidate key. 因此,在本例中,我们首先检查BE是否为候选密钥。 We find BE-closure consists of all the attributes of the relation R so it is the candidate key. 我们发现BE闭包由关系R的所有属性组成,因此它是候选关键字。 (Note: If BE would not have been the candidate key then we would have taken attributes from middle(M) column one-by-one and combine it with BE and check its closure eg. BEA , BEC , BED ...) (注意:如果BE不会成为候选关键字,那么我们应该从Middle(M)列中一对一地获取属性,并将其与BE结合起来,并检查其关闭情况,例如BEABECBED ...)

So now we have only 1 candidate key BE . 所以现在我们只有1个候选键BE So our prime attributes are {B,E} and non-prime attributes are {A,C,D,F} . 因此,我们的主要属性是{B,E}非主要属性是{A,C,D,F}

We know that 3NF is violated if RHS is a non-prime attribute and LHS is not a candidate key . 我们知道, 如果RHS是非主要属性并且LHS不是候选密钥 ,则会违反 3NF。 Given FD's are: 给定的FD是:

  1. AB->C AB-> C
  2. DBE->A DBE-> A
  3. BC->D BC-> D
  4. BE->F BE-> F
  5. F->D F→D

We note that in all these FD's RHS is a non-prime attribute. 我们注意到,在所有这些FD的RHS中,都是非主要属性。 So in all of these LHS should be a key for it to be in 3NF. 因此,所有这些LHS都应成为3NF的关键。 We see that (1),(3) and (5) violate this so it is not in 3NF . 我们看到(1),(3)和(5)违反了这一点,因此不在3NF中 ( Note: In (2) we can see that D on the LHS is an extraneous attribute so its BE->A and hence (2) does not violate 3NF rule ) 注意:在(2)中,我们可以看到LHS上的D是一个无关紧要的属性,因此它的BE->A ,因此(2)不违反3NF规则

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

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