You will have a table QUESTIONNAIRE-ITEMS (the questions) and a separate table QUESTIONNAIRE-RESPONSES (the answers), because there will be multiple answers for a single question, those from multiple persons. The former gets a foreign key to QUESTIONNAIRE, while the latter gets foreign keys to both QUESTIONNAIRE-ITEMS and PERSON.
In fact, the PERSON-QUESTIONNAIRE table could be omitted, since that information could be queried from the other tables. So for the design I suggest:
- Surveys: ID (PK), Description, etc...
- Users: ID (PK), Name, etc...
- Questions: ID (PK), SurveyID (FK), Question, etc...
- Answers: ID (PK), QuestionID (FK), UserID (FK), Answer, etc...
The view for the DBGrid will be based on a query like:
SELECT
Question,
Answer,
...
FROM
Questions INNER JOIN Answers ON Questions.ID = Answers.QuestionID
WHERE
Questions.SurveyID = :SurveyID AND Answers.UserID = :UserID
In another part of you GUI, you select the SurveyID
and UserID
parameters.
And as a bonus: the query to acquire surveys and users, as an alternative to your separate join table, will look like :
SELECT
Surveys.ID,
Users.ID
FROM
Users INNER JOIN (
Answers INNER JOIN (
Questions INNER JOIN (
Surveys
) ON Questions.SurveyID = Surveys.ID
) ON Answers.QuestionID = Questions.ID
) ON Users.ID = Answers.UserID
GROUP BY
Surveys.ID,
Users.ID