LuckyLuke
LuckyLuke

Reputation: 49077

Making a database containing answers, questions and categories

I made a question yesterday about this, but I did some changes in my structure.

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!

Upvotes: 0

Views: 172

Answers (2)

marc_s
marc_s

Reputation: 754508

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:

alt text

Upvotes: 2

Related Questions