函数依赖和多对多关系
Functional dependency and many-to-many relationships
我有这些字段:
A book_id
B book_title
C book_isbn
D book_year
G reader_id
H reader_name
I reader_birthday
L reader_phone
M reader_email
N reader_registration_date
O loan_id
P loan_date_issued
S loan_date_for_return
T loan_date_returned
U author_id
V author_name
W category_id
X category_name
以及这些依赖项:
A->BCD
G->HILMN
O->AGPST
U->AV
W->AX
经过所有计算我得到这个:
R1 = ABCD k1 = {A} Books
R2 = GHILMN k2 = {G} Readers
R3 = AGOPST k3 = {O} Loans
R4 = AUV k4 = {U} Authors
R5 = AWX k5 = {W} Category
R6 = OUW k6 = {OUW} {Don’t know}
但这并不好,因为 table 图书与 table 类别存在多对多关系,图书和作者 table 也是如此。
我卡住了。我认为我从一开始就做错了,然后一切都出错了。也许你有这方面的一些例子。
让我们将 "category" 视为 "book"-as-object 的 "cover" 或 "book"-as-text 的 "copy",其中 "book"与它特有的一些O值相关联。然后 W -> A 更直观。 (其他 FD 似乎也不直观。)
普遍关系
每个 table(基本或查询结果)都有一个谓词(语句模板),一行使该谓词成为真语句(并进入 table)或假语句(并且留在外面)。我们说 table 表示由谓词表征的业务 relationship/association。此处谓词的猜测是:
book A titled B with isbn C published in year D
was borrowed by a reader G named H born on date I
with phone# L and email address M registered on date N
in loan O issued on date P due on date S
and either it was returned on date T or it is not yet returned and T=NULL
and it was written by author U named V
and the library has A in cover/copy W named X
您似乎在使用 "universal relation" 分解 design/normalization 技术。但这仅适用于 table 满足 "universal relation assumption" 的情况。也就是说,您的所有情况都可以通过一个谓词及其一个 table.
来描述
例如:假设你可以有没有借出的书或者没有借出的用户。那么上面的例子predicate/table无法记录。所以分解将无法记录它们。所以你应该从一个不同的 predicate/table 开始。 (通常是多个。)
例如:如果最后一行是 and A was borrowed in cover/copy W named X
,那么 table 在给定情况下可以持有与之前不同的值。但根据借贷政策,table 可以满足同一组 FD。
什么是这个table的谓词?如果不是你猜的那样,可能达不到你的期望。
你分解
让我们忽略实体的属性。
-- O is G borrowing A by U with W
A book_id
G reader_id
O loan_id
U author_id
W cover/copy_id
O->AG
U->A
W->A
唯一的CK是OUW。这是对 BCNF 的明显分解。与你的版本一致。
-- O is G borrowing A by someone with some cover/copy
-- O is G borrowing A
Loan(O,G,A)
-- some loan is somebody borrowing A by U with some cover/copy
-- the book of U is A
The_book_of_author(U,A)
-- some loan is somebody borrowing A by someone with W
-- the book of W is A
The_book_of_cover/copy(W,A)
-- O is somebody borrowing some book by U with W
-- O is the borrowing of the book of U and W
Author_and_cover/copy(O,U,W)
原始关系是组件的连接:
-- O is G borrowing A
and the book of U is A
and the book of W is A
and O is the borrowing of the book of U and W
-- O is G borrowing A by U with W
Loan JOIN The_book_of_author JOIN The_book_of_cover/copy JOIN Author_and_cover/copy
this is not good because table Book has a many to many relationship with table Category, and so do the Book and Author tables
不幸的是,这是无法理解的。所以我无法解决你的意思是说错了。
数据库设计
如果您自己生成此设计,则应该使用一些参考信息建模方法。这将指导您确定合理的 predicates/tables 以记录根据您的业务规则可能出现的所有情况。
应用于可能出现的情况的谓词决定了可能出现的状态。这些有效状态由约束描述——FD(函数依赖)、JD(连接依赖)、CK(候选键)、FK(外键)(又名 "relationships",与上述不同),等等
方法的一部分是将临时 tables 标准化为其他方法。这使用 FD 和 JD 通过适当的算法分解为适当的 NF(正常形式)。一个好的方法总是归一化为 5NF。 (即使您稍后出于实现原因对其进行非规范化。)
我有这些字段:
A book_id
B book_title
C book_isbn
D book_year
G reader_id
H reader_name
I reader_birthday
L reader_phone
M reader_email
N reader_registration_date
O loan_id
P loan_date_issued
S loan_date_for_return
T loan_date_returned
U author_id
V author_name
W category_id
X category_name
以及这些依赖项:
A->BCD
G->HILMN
O->AGPST
U->AV
W->AX
经过所有计算我得到这个:
R1 = ABCD k1 = {A} Books
R2 = GHILMN k2 = {G} Readers
R3 = AGOPST k3 = {O} Loans
R4 = AUV k4 = {U} Authors
R5 = AWX k5 = {W} Category
R6 = OUW k6 = {OUW} {Don’t know}
但这并不好,因为 table 图书与 table 类别存在多对多关系,图书和作者 table 也是如此。 我卡住了。我认为我从一开始就做错了,然后一切都出错了。也许你有这方面的一些例子。
让我们将 "category" 视为 "book"-as-object 的 "cover" 或 "book"-as-text 的 "copy",其中 "book"与它特有的一些O值相关联。然后 W -> A 更直观。 (其他 FD 似乎也不直观。)
普遍关系
每个 table(基本或查询结果)都有一个谓词(语句模板),一行使该谓词成为真语句(并进入 table)或假语句(并且留在外面)。我们说 table 表示由谓词表征的业务 relationship/association。此处谓词的猜测是:
book A titled B with isbn C published in year D
was borrowed by a reader G named H born on date I
with phone# L and email address M registered on date N
in loan O issued on date P due on date S
and either it was returned on date T or it is not yet returned and T=NULL
and it was written by author U named V
and the library has A in cover/copy W named X
您似乎在使用 "universal relation" 分解 design/normalization 技术。但这仅适用于 table 满足 "universal relation assumption" 的情况。也就是说,您的所有情况都可以通过一个谓词及其一个 table.
来描述例如:假设你可以有没有借出的书或者没有借出的用户。那么上面的例子predicate/table无法记录。所以分解将无法记录它们。所以你应该从一个不同的 predicate/table 开始。 (通常是多个。)
例如:如果最后一行是 and A was borrowed in cover/copy W named X
,那么 table 在给定情况下可以持有与之前不同的值。但根据借贷政策,table 可以满足同一组 FD。
什么是这个table的谓词?如果不是你猜的那样,可能达不到你的期望。
你分解
让我们忽略实体的属性。
-- O is G borrowing A by U with W
A book_id
G reader_id
O loan_id
U author_id
W cover/copy_id
O->AG
U->A
W->A
唯一的CK是OUW。这是对 BCNF 的明显分解。与你的版本一致。
-- O is G borrowing A by someone with some cover/copy
-- O is G borrowing A
Loan(O,G,A)
-- some loan is somebody borrowing A by U with some cover/copy
-- the book of U is A
The_book_of_author(U,A)
-- some loan is somebody borrowing A by someone with W
-- the book of W is A
The_book_of_cover/copy(W,A)
-- O is somebody borrowing some book by U with W
-- O is the borrowing of the book of U and W
Author_and_cover/copy(O,U,W)
原始关系是组件的连接:
-- O is G borrowing A
and the book of U is A
and the book of W is A
and O is the borrowing of the book of U and W
-- O is G borrowing A by U with W
Loan JOIN The_book_of_author JOIN The_book_of_cover/copy JOIN Author_and_cover/copy
this is not good because table Book has a many to many relationship with table Category, and so do the Book and Author tables
不幸的是,这是无法理解的。所以我无法解决你的意思是说错了。
数据库设计
如果您自己生成此设计,则应该使用一些参考信息建模方法。这将指导您确定合理的 predicates/tables 以记录根据您的业务规则可能出现的所有情况。
应用于可能出现的情况的谓词决定了可能出现的状态。这些有效状态由约束描述——FD(函数依赖)、JD(连接依赖)、CK(候选键)、FK(外键)(又名 "relationships",与上述不同),等等
方法的一部分是将临时 tables 标准化为其他方法。这使用 FD 和 JD 通过适当的算法分解为适当的 NF(正常形式)。一个好的方法总是归一化为 5NF。 (即使您稍后出于实现原因对其进行非规范化。)