-2

Here are two ways I can optimise mapping of a text field with several other attributes to question and answer. First approach is, creating a map table with both question_id and answer_id in which either of them will be null, and while querying I will query using column. In the second approach is normal like we would do normalisation.

Tables structures

Second approach will add one more table but in first approach there will be empty values against question_id and answer_id. Questions-

  1. Is it a good practice to leave cells blank?
  2. Will it have any performance issue?
  3. Will it violate any normalisation rule?
  4. ...

1 Answers1

1

Step #1 is to decide clearly "What is your DB used for". Answer this:

  1. What is the way you/users write data in?
  2. What is the way users will query data out of the DB?
  3. What are your outputs? Other queries and representations of the data you will have inside.

  • If you are building just a storage for Q/A, one table is enough.
  • If you want to track multiple answers, or maybe a "chat", regarding the single question, two table are good to go. Table of questions (primary table) + table of answers (secondary table) with foreign key to the question (SQL DB approach).
  • If you are about to build a knowledge base, where one question can have multiple answers, based on "Symptoms" or something. Than in SQL it would involve 3 or more tables. (also consider using a Graph database or other NOSQL DB).