Most efficient database design for a blog (posts and comments)

后端 未结 5 2005
你的背包
你的背包 2021-01-31 12:15

What would be the best way of designing a database to store blog posts and comments? I am currently thinking one table for posts, and another for comments, each with a post ID.<

5条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 12:50

    try something like this:

    Blog
    BlogID     int auto number PK
    BlogName   string
    ...
    
    BlogPost
    BlogPostID   int auto number PK
    BlogID       int FK to Blog.BlogID, index
    BlogContent  string
    ....
    
    Comment
    CommentID       int auto number PK
    BlogPostID      int FK to BlogPost.BlogPostID, index   
    ReplyToCommentID int FK to Comment.CommentID  <

提交回复
热议问题