There is a wizard that can contain over 150 questions or just 10. Each question can be different from the question asked before. For example, it is possible that one question requires you to answer a “Yes / No” answer, but the next one can contain a multiple choice list with four options. There also should be an opportunity to fill in a completely open answer to the question asked in this wizard. The wizard consist of multiple sections.
The results of this wizard should also be evaluated. For example:
“Did you ever forget to put on your shoes when going to work?” “Yes/No” If the user answered yes, we should evaluate this and tell him that he should put his shoes at the door, so he won’t ever forget it again. (example)
The results of this wizard have to be saved into a database, but doing this in one table and just adding all data to this table looks quiet unhandy to me.
Is there anyone here that has a clean solution so that for example if we ever have to rebuild a wizard like this, we can just use the same database?
You definitely shouldn’t try to put it all in one big table. My design would look something like this:
Wizard
Id, Name, Preface, AnyOtherInfoYouMightWantToStore
Question
Id, WizardId, Question, SortNumber
Alternative
Id, QuestionId, TypeId (radio, checkbox, free-text, multiline freetext…), Name, SortNumber
Reply
Id, UserId (I imagine you’d have some user account solution), QuestionId, AlternativeId
Roughly like that. So that a wizard can contain many questions, and a question can contain many alternatives (yes + no radiobuttons would be one record each in Alternative table, but you could also do more complex things, such as a handful of checkboxes and, at the bottom, a “Other” textfield)