问题
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