database - 确定 super 键

标签 database database-design key 3nf bcnf

According to Wikipedia

Today's Court Bookings

enter image description here

  • Each row in the table represents a court booking at a tennis club that has one hard court (Court 1) and one grass court (Court 2)
  • A booking is defined by its Court and the period for which the Court is reserved
  • Additionally, each booking has a Rate Type associated with it. There are four distinct rate types:
    • SAVER, for Court 1 bookings made by members
    • STANDARD, for Court 1 bookings made by non-members
    • PREMIUM-A, for Court 2 bookings made by members
    • PREMIUM-B, for Court 2 bookings made by non-members

The table's superkeys are:

  • S1 = {Court, Start Time}
  • S2 = {Court, End Time}
  • S3 = {Rate Type, Start Time}
  • S4 = {Rate Type, End Time}
  • S5 = {Court, Start Time, End Time}
  • S6 = {Rate Type, Start Time, End Time}
  • S7 = {Court, Rate Type, Start Time}
  • S8 = {Court, Rate Type, End Time}
  • ST = {Court, Rate Type, Start Time, End Time}, the trivial superkey

Note that even though in the above table Start Time and End Time attributes have no duplicate values for each of them, we still have to admit that in some other days two different bookings on court 1 and court 2 could start at the same time or end at the same time. This is the reason why {Start Time} and {End Time} cannot be considered as the table's superkeys.

S1 = {法庭,开始时间}是一个 super 键吗?

假设在第 1 天,成员(member)在 11:00 至 12:00 期间预订球场 1,而在第 2 天,非成员(member)在 11:00 至 12:00 期间预订球场 1。

表中的记录将是 {1,11:00,12:00,节省}和{1,11:00,12:00,标准}

显然 S1 = {法庭,开始时间},不是 super key 。还是我错了?

最佳答案

这个例子是一个糟糕的选择,因为要理解表格应该包含什么内容,涉及到未阐明的、尽管是常识的假设。它希望您看到该表仅适用于一天(“今天”),并推断在任何一天都不会出现重叠预订。即,一个球场的开始结束时间段不会与同一球场的另一个开始结束时间段重叠。 (文本提到不同的日期意味着不同的表值;但对于示例来说,不同的值是否必须位于不同的日期并不重要。)

这对于 3NF 与 BCNF 来说尤其是一个糟糕的选择。当然,它受制于与 3NF 和 BCNF 相关的某些 FD(功能依赖性)及其关联的 JD(连接依赖性)。但预订的不重叠是一个单独的约束,与 3NF 与 BCNF 无关。

Say on day 1, a member books court 1 from 11:00 to 12:00, and on day 2, a non member books court 1 from 11:00 to 12:00.

当我们说“满足”约束(例如FD)或“受制于”约束或“具有”约束或约束“保存在”表中,我们的意思是该值使约束为真。当我们谈论表变量(基表)时,我们的意思是每个数据库状态下的变量值都是如此。对于这个表,描述了“今天”的当前预订情况,任何特定的预订情况都将是大约一天——今天。因此,报价中涉及不同日期的重叠与限制无关。同样,无论预订如何变化,同一天不同时间的每个表值都将满足约束本身。

在这些情况下,对于表的任何状态,四个指定的列集都是 CK(候选键):

  • S1 = {法庭,开始时间}
  • S2 = {法庭,结束时间}
  • S3 = {费率类型、开始时间}
  • S4 = {费率类型、结束时间}

由于预订不重叠,因此每个列集的子行值在这些列下都是唯一的。所以他们是 super key 。由于这对于每个子集都成立,因此它们是 CK。由于它对于其他列集均不成立,因此不存在其他 CK。由于 super key 的每个超集都是 super key ,因此列出的其他集合是其他(非 CK) super key 。

PS 该条目的 talk page 有几个部分。关于网球/预订示例和页面上的混淆。该页面还有其他不好的例子。例如,它将非 BCNF 3NF 设计重组为 BCNF 设计,但不是通过标准无损分解到原始投影(连接回原始投影)。 (它引入了一个新专栏。)例如,它还讨论了保留依赖关系,但这只有在分解为原始投影时才有意义。

关于database - 确定 super 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33537277/

相关文章:

database - PostgreSQL - 产品的最佳数据库模型和该产品的多种评级类型是什么?

python - 如何在单独的模块中管理 peewee 数据库?

c# - 数据库设计头脑 Storm : Sale Prices

dictionary - Elixir:重命名字典中的键

mysql - 我可以开始记录应用程序发起的 SQL 查询,以便了解它在做什么吗?

java - 在 java swing 中构建后,我的数据库会出现在 jar 文件中吗?

asp.net-core - 数据库中的本地化实体

mysql - 我应该如何存储网站的链表类型数据?

.net - RSA 私钥是否始终包含公钥,还是只是 .NET?

function - 如何在 Emacs 中将 F1-F12 键绑定(bind)为键盘宏?