gpt4 book ai didi

mysql - 正确的表结构

转载 作者:行者123 更新时间:2023-11-29 13:19:18 26 4
gpt4 key购买 nike

我需要一些有关此表结构的帮助,因为它比我预期的更复杂。我正在创建评论,但我不知道应该使用什么表结构。

我有多个表,用户可以在其中发表评论(如帖子、照片等),这需要 1 个标识符。每个项目都有自己的 id - 第二个标识符。每个评论都有自己的 id——第三个标识符。我的看法是有 3 列,分别是 id、item_id 和 table,但是你们告诉我,将表保存在表中并不好。我想不出任何其他结构。这可能是因为一旦我们的大脑被一个想法困住了,它就无法摆脱,或者可能只是因为我很笨。不管怎样,我真的很想在这里得到一些帮助,如果我能帮我解决这个问题那就太好了。

最佳答案

你可以这样做:

comments :

comment_id - primary key
comment - actual comment (mandatory)
user_id - user who post comments. (mandatory)
post_id - post id on which user comments (optional)
photo_id - user photo id on which user commented (optional)
etc as required.... then status, created_by, create_date, updated_by, updated_by

post_id 或 photo_id 都是必填项,因此您可以前往

这种方法很好,就好像您需要为其他任何东西(即视频)添加评论,然后只需添加 video_id

关于mysql - 正确的表结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21061046/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com