对不同数据库条目的注释

发布于 2024-12-14 10:33:29 字数 137 浏览 2 评论 0原文

例如,我有“新闻”和“文章”表,我想使用“评论”表评论这些条目。

在此处输入图像描述

建立关系和评论不同条目的最佳方式是什么?

For example, I have "news" and "articles" tables and I want comment these entries using "comments" table.

enter image description here

What the best way to make relationship and comment different entries?

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

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

发布评论

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

评论(1

家住魔仙堡 2024-12-21 10:33:29

我假设新闻和文章到评论都是一对多的。我还假设相同的评论不能同时关联到新文章和文章。

其中一种方法是:

在此处输入图像描述

优点是架构标准化,数据完整性得到正确维护,并且允许模式演变。例如,将来可能有可能为另一种类似的实体添加评论(例如允许为博客表添加评论)。

缺点是查询新闻或文章的评论时需要额外加入表

I assume both news and articles to comments are one-to-many . And I also assume the same comment cannot associate to a new and an article at the same time.

One of the way is that:

enter image description here

Advantages is that the Schema is normalized ,data integrity is properly maintained and it allows for schema evolution. For example , there may be possibility to add the comment for another similar kind of entity in the future (eg Allow adding comments for the blog table).

Disadvantages is that it requires join extra table when query the comments for a news or articles

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