I’m creating an application that asks the user a question and demands an answer in the form of a country.
For example: Where is the Eifell Tower located?
The user is presented with a number of alternatives, lets say 10 different countries.
The problem arrises when I want to store every answer to a mySQL-database. I have a table with all the countries, and need to store which of them were included in the question. However, doing it this way would create, in this case, 10 database rows for a single answered question. I’ve been looking into storing the included countries as a bit mask, but a single bit mask wouldn’t be enough with over 150 possible countries.
Any help on what would be a good way to store the data is much appreciated!
Thanks!
I’d just store The relation in a table like you are suggesting. I.e, three tables where the first contains questions (Id, question_text, ..), the second table contains all the countries (Id, name, ..) and the third table contains the relation that says what country is an option in which question (question_id, country_id). Like you say this gives ten rows in the relationship table for a single question, but are you really facing a storage space or performance problem here?
If you have 10k such questions, it is still just 100k rows and less than a megabyte of data. The questions themselves will have a lot more data than that, so the relation between question and country shouldn’t be an issue as far as I can see.