删除包含连接消息的页面的最佳方法?

发布于 2025-01-06 18:42:55 字数 335 浏览 3 评论 0原文

我有一个用一大堆“提要项目”创建的页面 - 就像 Facebook - 我目前面临的问题是找出“删除逻辑”的最佳方法。也就是说,如果用户删除一个页面 - 我想删除此页面的“连接消息”,即:

  1. 提要项目
  2. 评论

我有许多保存提要项目、评论等的 MySQL 表 - 但我不确定如果用户删除页面,删除所有这些的最“最佳方式”?

有人可以提供建议吗?我想它类似于 StackOverflow - 如果删除问题,删除

  1. 问题答案
  2. 所有评论

等的最佳方法是什么?

I have a page that I have created with a whole bunch of 'feed items' - like facebook - the problem I am currently facing is the best way to figure out 'delete logic'. That is, if a user deletes a PAGE - I want to remove the "connected messages" to this page that is:

  1. feed items
  2. comments
  3. etc

I have a number of MySQL tables that hold feedItems, comments etc - but I'm unsure of the most "optimal way" to remove all this if a user deletes a page ?

Would someone be able to advise ? I guess its similar to StackOverflow - if a question is delete, what's the best way to delete

  1. the question
  2. the answers
  3. all the comments

etc ?

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

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

发布评论

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

评论(1

何其悲哀 2025-01-13 18:42:55

如果您使用 InnoDB,最简单的方法是在外键上使用 ON DELETE CASCADE。当外键引用的行被删除时,此选项使 MySQL 删除表中的行。

例如,如果您有一个带有主键 ID 的表“question”,以及一个带有外键“question_id”的表“answers”,则当删除该问题时,“answers”中包含相同 Question_id 的所有行也会被删除。

否则,您需要编写多个删除语句,每个表一个。

If you're using InnoDB, the easiest way use the ON DELETE CASCADE on you foreign keys. This option makes MySQL delete rows in tables when the row to which the foreign key refers to is deleted.

For instance, if you have a table "question" with a primary key ID, and a table "answers" with a foreign key "question_id", when the question will be deleted, all the rows in "answers" that contains the same question_id will be deleted too.

Else you need to write multiple delete statements, one for each table.

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