开发者

Making a database containing answers, questions and categories

I made a question yesterday about this, but I did some changes in my structu开发者_运维问答re.

I have one table containing the questions(foreign key to the category ID). One table containing the categories and one table containing the answers with foreign key to the question table(and primary key which is the answer ID together with the foreign ID).

But my question is, how do I structure my database when one question belongs to multiple categories?

Thanks in advance!


In that case, you need a "link" table between questions and categories - something like:

Question_Categories

QuestionID (FK into table Questions)
CategoryID (FK into table Category)

Using that approach, any question can belong to any number of categories, and any category can have any number of questions associated with it.

Structure would look something like this:

Making a database containing answers, questions and categories


See What is the most efficient way to store tags in a database?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜