数据库规范化 (3NF) - 外键
Database Normalization (3NF) - Foreign keys
在尝试理解 3NF 之后,我遇到了一个小问题,我不确定自己是否理解正确。
结构组件出现问题如下:
s = {
Product(ProductID, ProductName, ProductDescription, SupplierName, SupplierAddress, SupplierID)
}
F = {
ProductID -> ProductName, ProductDescription
SupplierID -> SupplierName, SupplierAddress
}
当然,默认情况下,我会将 SupplierName 和 SupplierAddress 都移动到不同的实体/table。问题以 SupplierID 的形式出现。我不知道是否可以将 SupplierID 保留在 Product table / entity.
事实是,SupplierID 不依赖于 ProductID(因为它写在 F 中)。我相信把它放到第三个table(如下)就可以了。
S = {
Products(ProductID, ProductName, ProductDescription),
Suppliers(SupplierID, SupplierName, SupplierAddress),
PS(ProductID, SupplierID)
}
但是,如果我将 SupplierID 放入 Products table(根本没有 "PS" table),3NF 仍然可以吗?
三个关系的分解在 3NF 中是正确的,而如果您将 SupplierID 放在 Product table 中,您获得的关系甚至不在 2NF 中。
其实在关系中:
R1(ProductDescription, ProductID, ProductName, SupplierID)
由于以下两个依赖关系成立:
ProductID → ProductName
ProductID → ProductDescription
关系的(唯一)候选键是(ProductID,SupplierID)。这意味着前面两个依赖项违反了 3NF,因为左侧不是超键,右侧是非素数属性。
在尝试理解 3NF 之后,我遇到了一个小问题,我不确定自己是否理解正确。
结构组件出现问题如下:
s = {
Product(ProductID, ProductName, ProductDescription, SupplierName, SupplierAddress, SupplierID)
}
F = {
ProductID -> ProductName, ProductDescription
SupplierID -> SupplierName, SupplierAddress
}
当然,默认情况下,我会将 SupplierName 和 SupplierAddress 都移动到不同的实体/table。问题以 SupplierID 的形式出现。我不知道是否可以将 SupplierID 保留在 Product table / entity.
事实是,SupplierID 不依赖于 ProductID(因为它写在 F 中)。我相信把它放到第三个table(如下)就可以了。
S = {
Products(ProductID, ProductName, ProductDescription),
Suppliers(SupplierID, SupplierName, SupplierAddress),
PS(ProductID, SupplierID)
}
但是,如果我将 SupplierID 放入 Products table(根本没有 "PS" table),3NF 仍然可以吗?
三个关系的分解在 3NF 中是正确的,而如果您将 SupplierID 放在 Product table 中,您获得的关系甚至不在 2NF 中。
其实在关系中:
R1(ProductDescription, ProductID, ProductName, SupplierID)
由于以下两个依赖关系成立:
ProductID → ProductName
ProductID → ProductDescription
关系的(唯一)候选键是(ProductID,SupplierID)。这意味着前面两个依赖项违反了 3NF,因为左侧不是超键,右侧是非素数属性。