这个设计符合5NF吗?

发布于 2024-12-07 09:40:40 字数 267 浏览 0 评论 0原文

一名用户只能拥有一个博客(该用户拥有该博客)
博客可以有多个帖子。
群组只能有一个博客(但没有特定用户拥有该博客,假设群组所有者创建了该博客,因此 userid 只是用户博客的属性,而不是群组博客的属性,因此需要子类型)

在此处输入图像描述

当删除 group_blog_post 时,底层的 blog_posts 行也应该被删除,这是最好使用触发器来完成吗?

A user can have only one blog (the user owns the blog)
Blogs can have multiple posts.
Groups can have only one blog (but no particular user owns the blog, it is assumed the group owner created the blog thus userid is only an attribute of user blogs not group blogs so subtyping is needed)

enter image description here

When group_blog_post is deleted, the underlying blog_posts row should be deleted as well, is this best accomplished using a trigger?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏闹i 2024-12-14 09:40:40

要使表处于 5NF 状态,它必须首先处于 4NF 状态。要处于 4NF 状态,必须首先处于 3NF 状态。依此类推,直至 1NF。

宽松地说,较低的范式与候选键和非素数属性之间的依赖关系有关。但我们能看到的唯一非素数属性是“title”和“is_private”。所以实在没办法说清楚。

以一张表为例,如果“group_users”没有其他列,则属于 5NF。

稍后

如果您像这样扩展表 group_users

create table group_users (
  group_id integer not null references groups (group_id),
  user_id integer not null refrences users (user_id),
  user_type_id integer not null references user_types (user_type_id),
  primary key (group_id, user_id)
);

那么您仍然处于 5NF 状态。 “user_type_id”列不仅仅依赖于 user_id——如果是的话,你就不会处于 2NF 中。但 user_type_id 不仅仅是用户的属性;它是用户的属性。它是该特定组中用户的一个属性。没有部分关键依赖;没有传递依赖;没有独立的、多值的事实;没有连接依赖性;所以它是5NF。

该结构只允许每个组的每个用户有一个 user_type_id。如果您认为用户应该在每个组中拥有多种用户类型,那么这

create table group_users (
  group_id integer not null references groups (group_id),
  user_id integer not null refrences users (user_id),
  user_type_id integer not null references user_types (user_type_id),
  primary key (group_id, user_id, user_type_id)
);

也是 5NF 中的情况。没有部分关键依赖;没有传递依赖;没有独立的、多值的事实;没有连接依赖性;所以它是5NF。

For a table to be in 5NF, it must first be in 4NF. To be in 4NF, it must first be in 3NF. And so on, down to 1NF.

Loosely speaking, the lower normal forms have to do with dependencies between candidate keys and non-prime attributes. But the only non-prime attributes we can see are "title" and "is_private". So there's really no way to tell.

To take one table as an example, "group_users" is in 5NF if it has no other columns.

Later

If you extend the table group_users like this

create table group_users (
  group_id integer not null references groups (group_id),
  user_id integer not null refrences users (user_id),
  user_type_id integer not null references user_types (user_type_id),
  primary key (group_id, user_id)
);

then you're still in 5NF. The column "user_type_id" isn't dependent only on user_id--if it were, you wouldn't be in 2NF. But the user_type_id isn't an attribute of the user alone; it's an attribute of the user in this particular group. No partial key dependencies; no transitive dependencies; no independent, multi-valued facts; no join dependencies; so it's in 5NF.

That structure allows only one user_type_id per user per group. If you think users should have multiple user types in each group, then this

create table group_users (
  group_id integer not null references groups (group_id),
  user_id integer not null refrences users (user_id),
  user_type_id integer not null references user_types (user_type_id),
  primary key (group_id, user_id, user_type_id)
);

is also in 5NF. No partial key dependencies; no transitive dependencies; no independent, multi-valued facts; no join dependencies; so it's in 5NF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文