Database about a forum design issue

眉间皱痕 提交于 2019-12-10 12:18:59

问题


I am currently designing a database about a forum.

The database will have for now the current tables - A table about the users, about the categories. The problem comes when I want to add the QuestionAndComments table. The QuestionAndComments table must have UserId(a foreign key pointing to the users table) and ParentId (will be null if it is a question and will have some value if it is a comment - the comment could be to a question or to an other comment) of the question but it must also contain the CategoryId(Foreign key referencing the categories table).

The problem is that if it's a comment it shouldn't have a CategoryId, it should have a CategoryId if it's only a question. Anyway if I try splitting the tables to table "Questions" and table "Comments" then I would ruin the self reference to the "QuestionsAndComments" table.

Surely the "Comments" table could point to the "Questions" table but then the "Comments" table must be self reference to itself and also point to the "Questions" table which is nonsense.

来源:https://stackoverflow.com/questions/47740089/database-about-a-forum-design-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!