Perfect Database Model for Tags?

I am building a Q&A website. For each Question there are several tags. Which is the best database model for this use case? Please tell me of the current options:

Option 1:
QuestionTable (one) → QuestionTag (many tags), and another field of type Question (multiple for each Tag).

I can see the problem in this model that there maybe millions of #tags and for each tag millions of questions in each entry for QuestionTag table. Isn’t this going to blow my database app when it scales?

Option 2
QuestionTable (one) → QuestionTag (one), there is field of type text (Tag) with multiple values. So for each QuestionID, there will be multiple tags in the same database record.

I am currently going with Option 2, but facing a technical problem where the list of texts (tags) are not seen as separate entities when seen from a dropdown list. I have tried checking on the forum for this problem in this inquiry but still it’s not clear how I can do it.

image

So as you can see in this image the list of texts are shown on the same line in the dropdown list.

Appreciate your knowledge to learn 2 things:

  1. Which DB model option is best, 1 or 2?
  2. If I go with option 2, how do I separate list of texts to be one entry for each line?

The items should be in an array (what Bubble calls a list). If a “Tag” is something important in your data model, it should be its own data type, so that you can do things like retrieve all Tags with certain criteria via a search.

Some other object (of some other type) can then have a Tag or list of Tags attached to it.

2 Likes