将关系转换为 3NF
Converting a relation into 3NF
给定的 FD 是 -
Epmployee#→Dept#,Manager#
Dept#→Manager#
course#→course_title
table就是-
我把它分解成了3个关系。他们在 3NF 中。
R1 (Employee#, Dept#) --- Employee is PK
R2 (Employee#, Course#, course_title, date) --- Emp# and Course# are PK
R3 (Dept#, Manager#) --- Dept# is PK
主键如上。
但是,当我将数据插入R2时,出现主键冲突。它是红色的。 我哪里错了?任何帮助将非常感激。
错误是因为您的table中已有这样的记录。结帐
002 ta01 Time Management 2014
仅供参考,这不是第三范式。课程名称不应出现在 R2 中。您应该有一个名为 table 的课程,它存储 Course Number, Course title
并且它只是应该出现在 R2
中的课程编号(TA01 等)
您的案例的正确分解如下:
R1(Dept#, Manager#), with the only dependency Dept# → Manager#, so Dept# is the key
R2(Employee#, Dept#), with the only dependency Employee# → Dept#, with key Employee#
R3(Course#, Course_title), with the only dependency Course# → Course_title and key Course#
R4(Employee#, Course#, Date), with no dependency and key (Employee#, Course#, Date)
所有关系都是 Boyce-Codd 范式(因此它们也是 3NF)。
最后请注意,人们可能会试图合并 R2 和 R4 这两个关系,但这会产生 4NF 中不存在的分解(因为一名员工只有一个部门,但可以学习多个课程)。
--- Emp# and Course# are PK
注意 PK(主键)与规范化无关。 CK(候选键)很重要。
{employee#, course#} 不是 R2 的 CK,因为它不能确定日期。唯一的 CK 是 {employee#, course#, date}。
They are in 3NF.
R2 不在 3NF 或 2NF 中,因为 non-prime 列 course_name 在功能上部分依赖于 CK,因为它在功能上依赖于 {course#},proper/smaller CK 的子集。 (即使 CK 是您声称的 {employee#, course#} 也是如此。)无损分解导致 3NF tables on {course#, course_title} 和 {employee#, course #, 日期}.
Course# -> Course_title
这对原始 table 没有意义,因为那些不是它的列。说一门课程只有一个标题是有道理的。这确实意味着在具有明显含义的那些列的 table 中,{course#} -> {course_title}。这也意味着原始的table受到了一定的约束;它只是不是 FD(功能依赖)约束。
it is written that if there are multi-valued attributes then I should form a new table and propagate the Primary key of the table (Employee#) into the new Table and them both the composite PK. [comment by you]
原来table每个训练值都是一组记录。要摆脱不属于 CK 的 set 列,我们可以使用某些 CK 的列拆分 table 以获得新的 table原始 table CK 子行值与集合元素的每一对对应的一行。这里的集合元素是记录。在我们去掉 set 列之后,我们可以去掉 record 列。为了摆脱 record 列,我们将其替换为字段的列。 现在应用那个给你的R2。
最初删除 table-valued 列被 Codd 称为 "normalization"。然后 "further normalization" Codd 意味着无损分解为更高的范式。有时删除 set-valued 或 record-valued 列称为 "normalization"。但事实并非如此。只是改进设计。有时 "normalization" 用于表示无损分解为更高范式,而不管任何 table-valued 列。
I created a different table R2 for that, and R2 is already in 2NF [comment by you]
每次用其他人替换 table 时,您必须确定新的 table 的 FD、CK 和 NF。如果您无损分解为更高的 NF,那么您就会知道每个组件的最高 NF 都高于原始组件。但在这里您正在执行 不同的 转换——摆脱设置和记录列。这里 R2 的 CK 和涉及课程的 FD 意味着它不在 2NF 中,即使原来是。 non-FD 涉及原始关系中课程的约束导致某个 FD 在 R2 中成立。
I feel the date should have been a part of some FD. [comment by you]
也许你想说的是你希望给定的员工在一年内只能参加给定的课程。但这不是我们被告知的。
给定的 FD 是 -
Epmployee#→Dept#,Manager#
Dept#→Manager#
course#→course_title
table就是-
我把它分解成了3个关系。他们在 3NF 中。
R1 (Employee#, Dept#) --- Employee is PK
R2 (Employee#, Course#, course_title, date) --- Emp# and Course# are PK
R3 (Dept#, Manager#) --- Dept# is PK
主键如上。
但是,当我将数据插入R2时,出现主键冲突。它是红色的。
错误是因为您的table中已有这样的记录。结帐
002 ta01 Time Management 2014
仅供参考,这不是第三范式。课程名称不应出现在 R2 中。您应该有一个名为 table 的课程,它存储 Course Number, Course title
并且它只是应该出现在 R2
您的案例的正确分解如下:
R1(Dept#, Manager#), with the only dependency Dept# → Manager#, so Dept# is the key
R2(Employee#, Dept#), with the only dependency Employee# → Dept#, with key Employee#
R3(Course#, Course_title), with the only dependency Course# → Course_title and key Course#
R4(Employee#, Course#, Date), with no dependency and key (Employee#, Course#, Date)
所有关系都是 Boyce-Codd 范式(因此它们也是 3NF)。
最后请注意,人们可能会试图合并 R2 和 R4 这两个关系,但这会产生 4NF 中不存在的分解(因为一名员工只有一个部门,但可以学习多个课程)。
--- Emp# and Course# are PK
注意 PK(主键)与规范化无关。 CK(候选键)很重要。
{employee#, course#} 不是 R2 的 CK,因为它不能确定日期。唯一的 CK 是 {employee#, course#, date}。
They are in 3NF.
R2 不在 3NF 或 2NF 中,因为 non-prime 列 course_name 在功能上部分依赖于 CK,因为它在功能上依赖于 {course#},proper/smaller CK 的子集。 (即使 CK 是您声称的 {employee#, course#} 也是如此。)无损分解导致 3NF tables on {course#, course_title} 和 {employee#, course #, 日期}.
Course# -> Course_title
这对原始 table 没有意义,因为那些不是它的列。说一门课程只有一个标题是有道理的。这确实意味着在具有明显含义的那些列的 table 中,{course#} -> {course_title}。这也意味着原始的table受到了一定的约束;它只是不是 FD(功能依赖)约束。
it is written that if there are multi-valued attributes then I should form a new table and propagate the Primary key of the table (Employee#) into the new Table and them both the composite PK. [comment by you]
原来table每个训练值都是一组记录。要摆脱不属于 CK 的 set 列,我们可以使用某些 CK 的列拆分 table 以获得新的 table原始 table CK 子行值与集合元素的每一对对应的一行。这里的集合元素是记录。在我们去掉 set 列之后,我们可以去掉 record 列。为了摆脱 record 列,我们将其替换为字段的列。 现在应用那个给你的R2。
最初删除 table-valued 列被 Codd 称为 "normalization"。然后 "further normalization" Codd 意味着无损分解为更高的范式。有时删除 set-valued 或 record-valued 列称为 "normalization"。但事实并非如此。只是改进设计。有时 "normalization" 用于表示无损分解为更高范式,而不管任何 table-valued 列。
I created a different table R2 for that, and R2 is already in 2NF [comment by you]
每次用其他人替换 table 时,您必须确定新的 table 的 FD、CK 和 NF。如果您无损分解为更高的 NF,那么您就会知道每个组件的最高 NF 都高于原始组件。但在这里您正在执行 不同的 转换——摆脱设置和记录列。这里 R2 的 CK 和涉及课程的 FD 意味着它不在 2NF 中,即使原来是。 non-FD 涉及原始关系中课程的约束导致某个 FD 在 R2 中成立。
I feel the date should have been a part of some FD. [comment by you]
也许你想说的是你希望给定的员工在一年内只能参加给定的课程。但这不是我们被告知的。