在 Mysql(或任何)数据库中存储请求的正确方法

发布于 2024-12-02 06:22:06 字数 223 浏览 2 评论 0原文

在数据库中存储请求的“正确”(最规范化?)方法是什么?例如,用户提交一篇文章。本文在发布到网站之前必须经过审查和批准。

哪种方法更合适:

A)将其存储在带有“已批准”字段的文章表中,该字段为 0、1、2(拒绝、批准、待定)

B)拥有具有相同字段的 ArticleRequests 表作为文章,并在获得批准后,将行数据从文章请求移动到文章。

谢谢!

What is the "proper" (most normalized?) way to store requests in the database? For example, a user submits an article. This article must be reviewed and approved before it is posted to the site.

Which is the more proper way:

A) store it in in the Articles table with an "Approved" field which is either a 0, 1, 2 (denied, approved, pending)

OR

B) Have an ArticleRequests table which has the same fields as Articles, and upon approval, move the row data from ArticleRequests to Articles.

Thanks!

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

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

发布评论

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

评论(3

温柔少女心 2024-12-09 06:22:06

由于每篇文章都会有一个批准状态,并且每次请求一篇文章时,您很可能需要知道该状态 - 使其与表格保持一致。

不过,请考虑调用该字段ApprovalStatus。您可能需要添加一个相关表来包含每个状态,除非它们不会经常(或永远)更改。

编辑:在相关表中保留字段的原因是:

  • 如果相关字段并不总是适用,或者可能经常为null
  • 如果相关字段仅在极少数情况下需要,并且通过使用外键到关联属性的相关表中来更好地描述。

对于您的情况,上述原因不适用。

Since every article is going to have an approval status, and each time an article is requested you're very likely going to need to know that status - keep it inline with the table.

Do consider calling the field ApprovalStatus, though. You may want to add a related table to contain each of the statuses unless they aren't going to change very often (or ever).

EDIT: Reasons to keep fields in related tables are:

  • If the related field is not always applicable, or may frequently be null.
  • If the related field is only needed in rare scenarios and is better described by using a foreign key into a related table of associated attributes.

In your case those above reasons don't apply.

冷情妓 2024-12-09 06:22:06

一定要做“A”。

如果您执行 B,您将创​​建一个与另一个表具有相同字段的新表,这意味着您做错了什么。你在重复自己。

Definitely do 'A'.

If you do B, you'll be creating a new table with the same fields as the other one and that means you're doing something wrong. You're repeating yourself.

如何视而不见 2024-12-09 06:22:06

我认为最好将具有特定状态的数据存储在主表中。因为如果此一项获得批准,则无需在表之间移动数据,并且该文章将同时出现在网站上。如果您不想存储未批准的文章,您应该创建 cron 脚本,删除不必要的数据或将它们移至存档表。在这种情况下,您的数据库负载将会减少,因为您可以调整适当的时间来删除旧文章,例如在晚上。

关于在每个查询中使用审批状态的问题:如果您计划拥有非常受欢迎的高负载站点来搜索或制作文章列表,您将使用独立服务器,例如 sphinx 或 solr(mysql 不是用于此目的的良好解决方案)并且您将把数据放入这些状态=“已批准”的状态。使用增量索引可帮助您保持数据最新。

I think it's better to store data in main table with specific status. Because it's not necessary to move data between tables if this one is approved and the article will appear on site at the same time. If you don't want to store disapproved articles you should create cron script with will remove unnecessary data or move them to archive table. In this case you will have less loading of your db because you can adjust proper time for removing old articles for example at night.

Regarding problem using approval status in each query: If you are planning to have very popular site with high-load for searching or making list of article you will use standalone server like sphinx or solr(mysql is not good solution for this purposes) and you will put data to these ones with status='Approved'. Using delta indexing helps you to keep your data up-to-date.

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