Survey database design: associate an answer to a user The 2019 Stack Overflow Developer Survey...

Deal with toxic manager when you can't quit

Does Parliament need to approve the new Brexit delay to 31 October 2019?

Is there a writing software that you can sort scenes like slides in PowerPoint?

University's motivation for having tenure-track positions

Are spiders unable to hurt humans, especially very small spiders?

How did passengers keep warm on sail ships?

How do I design a circuit to convert a 100 mV and 50 Hz sine wave to a square wave?

Do I have Disadvantage attacking with an off-hand weapon?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

Why not take a picture of a closer black hole?

Is an up-to-date browser secure on an out-of-date OS?

What do I do when my TA workload is more than expected?

Word to describe a time interval

What aspect of planet Earth must be changed to prevent the industrial revolution?

Can I visit the Trinity College (Cambridge) library and see some of their rare books

Was credit for the black hole image misappropriated?

Example of compact Riemannian manifold with only one geodesic.

Are there continuous functions who are the same in an interval but differ in at least one other point?

Do working physicists consider Newtonian mechanics to be "falsified"?

How to read αἱμύλιος or when to aspirate

Why can't wing-mounted spoilers be used to steepen approaches?

how can a perfect fourth interval be considered either consonant or dissonant?

Loose spokes after only a few rides

Can withdrawing asylum be illegal?



Survey database design: associate an answer to a user



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How does one create a data base for a survey/questionnaire?Survey database design: first version. Are there errors?Design question about student assessment datadb schema for a object with multiple foreign key tablesSurvey database design: first version. Are there errors?desing the database for survey app with various types of answersDesign of MySQLTable design question for a `Check all that apply` surveyDynamic Survey DB DesignBest data modelling approach to handle redundant foreign keys in a database about Surveys, Questions and ResponsesDatabase design for surveys and experimentsSurvey database with different types of usersWorking on a decision tree database designDesigning a data model for a survey; building the relationships





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







11















I'm doing the conceptual model for a survey database.



The goal is store the answers given by users (it's going to be an Android app).



I have three entities: user, question and option.



A question will have one or more options (for example: How many employees do you have? 1-40, 40-1000, +1000).



Options will have a text (1-40) and a value (the value selected by user).



User will select one (or more) of these options.



My conceptual design is:



enter image description here



I don't know how to associate an answer with an user.



How can I represent that relation?

Do I have another entity to represent option value?



This model will store questions and pre-made answers (offered answers) and allows them to be re-used in different surveys.



I have to represent question like this one:



enter image description here



This question is related to this one: Survey database design: first version. Are there errors?










share|improve this question




















  • 1





    Looks like you will need another table to handle the many-to-many relationship between Users and Options.

    – OliverAsmus
    Apr 3 '12 at 13:17


















11















I'm doing the conceptual model for a survey database.



The goal is store the answers given by users (it's going to be an Android app).



I have three entities: user, question and option.



A question will have one or more options (for example: How many employees do you have? 1-40, 40-1000, +1000).



Options will have a text (1-40) and a value (the value selected by user).



User will select one (or more) of these options.



My conceptual design is:



enter image description here



I don't know how to associate an answer with an user.



How can I represent that relation?

Do I have another entity to represent option value?



This model will store questions and pre-made answers (offered answers) and allows them to be re-used in different surveys.



I have to represent question like this one:



enter image description here



This question is related to this one: Survey database design: first version. Are there errors?










share|improve this question




















  • 1





    Looks like you will need another table to handle the many-to-many relationship between Users and Options.

    – OliverAsmus
    Apr 3 '12 at 13:17














11












11








11


10






I'm doing the conceptual model for a survey database.



The goal is store the answers given by users (it's going to be an Android app).



I have three entities: user, question and option.



A question will have one or more options (for example: How many employees do you have? 1-40, 40-1000, +1000).



Options will have a text (1-40) and a value (the value selected by user).



User will select one (or more) of these options.



My conceptual design is:



enter image description here



I don't know how to associate an answer with an user.



How can I represent that relation?

Do I have another entity to represent option value?



This model will store questions and pre-made answers (offered answers) and allows them to be re-used in different surveys.



I have to represent question like this one:



enter image description here



This question is related to this one: Survey database design: first version. Are there errors?










share|improve this question
















I'm doing the conceptual model for a survey database.



The goal is store the answers given by users (it's going to be an Android app).



I have three entities: user, question and option.



A question will have one or more options (for example: How many employees do you have? 1-40, 40-1000, +1000).



Options will have a text (1-40) and a value (the value selected by user).



User will select one (or more) of these options.



My conceptual design is:



enter image description here



I don't know how to associate an answer with an user.



How can I represent that relation?

Do I have another entity to represent option value?



This model will store questions and pre-made answers (offered answers) and allows them to be re-used in different surveys.



I have to represent question like this one:



enter image description here



This question is related to this one: Survey database design: first version. Are there errors?







database-design






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 15 mins ago







VansFannel

















asked Apr 3 '12 at 13:05









VansFannelVansFannel

7014928




7014928








  • 1





    Looks like you will need another table to handle the many-to-many relationship between Users and Options.

    – OliverAsmus
    Apr 3 '12 at 13:17














  • 1





    Looks like you will need another table to handle the many-to-many relationship between Users and Options.

    – OliverAsmus
    Apr 3 '12 at 13:17








1




1





Looks like you will need another table to handle the many-to-many relationship between Users and Options.

– OliverAsmus
Apr 3 '12 at 13:17





Looks like you will need another table to handle the many-to-many relationship between Users and Options.

– OliverAsmus
Apr 3 '12 at 13:17










5 Answers
5






active

oldest

votes


















7














You need to make a distinction between the possible answers and the selected answers.



The Option table needs to be two tables. The Option table should be 1:M to Question and should include the possible answers for that question.



Then you need to make a new intersection entity, call it Selected_Option which sits between User and Option.



If your question gives the user an opportunity to fill in a value as an answer (i.e. "OTHER:...") then this value would be stored in the Selected_Option table. Otherwise the value chosen by the user would be the value found in Option.





EDIT:



Based on OP's clarification of requirements: What you need is not like a typical questionnaire model in the following ways:




  • Your questions all have the same sets of answers (columns)

  • Some of your answers (columns) are grouped together.

  • Blocks of questions are grouped together.


Taking your form snapshot as a guide, I've divided up the elements of your form into entities which I've colour coded:



Colour Coded Form Example



This could be accomodated by the following logical ERD:



Logical ERD



Note that I've colour coded the entities in the ERD to correspond to the snapshot of your sample form to show the correlation.



One of the assumptions in this model is that each block has only one set of quesitons (i.e. one QUESTION_GROUP) which corresponds to the left-hand column in the block. This is a bit of a simplifying assumption.






share|improve this answer


























  • I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 6:58






  • 1





    @VansFannel - I've updated my answer to reflect your edited question.

    – Joel Brown
    Apr 4 '12 at 12:24











  • Thank you very much! You have helped me a lot. I have added my final design as a question here: dba.stackexchange.com/questions/16066/… You can check it if you wish.

    – VansFannel
    Apr 4 '12 at 12:26













  • One question: What does it mean "sequence" and "value"? I haven't worked so much with ERD (sorry).

    – VansFannel
    Apr 4 '12 at 12:54











  • @VansFannel - The attribute notes in the ERD are just non-trivial (or non-obvious) columns in the tables. I expect that you'd guess where to put IDs, FKs, descriptions, etc. For sequence I'm suggesting that you'll need/want to control the order in which items are displayed. For value I'm pointing out that a user-entered value (not just an option selection) may be appropriate.

    – Joel Brown
    Apr 4 '12 at 19:30



















12














This is a real classic, done by thousands. They always seems 'fairly simple' to start with but to be good it's actually pretty complex. To do this in Rails I would use the model shown in the attached diagram. I'm sure it seems way over complicated for some, but once you've built a few of these, over the years, you realize that most of the design decisions are very classic patterns, best addressed by a dynamic flexible data structure at the outset.

More details below:



enter image description here




Table details for key tables




answers



The answers table is critical as it captures the actual responses by users.
You'll notice that answers links to question_options, not questions. This is intentional.



input_types



input_types are the types of questions. Each question can only be of 1 type, e.g. all radio dials, all text field(s), etc. Use additional questions for when there are (say) 5 radio-dials and 1 check box for an "include?" option or some such combination. Label the two questions in the users view as one but internally have two questions, one for the radio-dials, one for the check box. The checkbox will have a group of 1 in this case.



option_groups



option_groups and option_choices let you build 'common' groups.
One example, in a real estate application there might be the question 'How old is the property?'.
The answers might be desired in the ranges:
1-5
6-10
10-25
25-100
100+



Then, for example, if there is a question about the adjoining property age, then the survey will want to 'reuse' the above ranges, so that same option_group and options get used.



units_of_measure



units_of_measure is as it sounds. Whether it's inches, cups, pixels, bricks or whatever, you can define it once here.



FYI: Although generic in nature, one can create an application on top of this, and this schema is well-suited to the Ruby On Rails framework with conventions such as "id" for the primary key for each table. Also the relationships are all simple one_to_many's with no many_to_many or has_many throughs needed. I would probably add has_many :throughs and/or :delegates though to get things like survey_name from an individual answer easily without.multiple.chaining.






share|improve this answer
























  • Great! Thanks for your answer. I will learn a lot with it. Thank you.

    – VansFannel
    Apr 21 '12 at 14:19











  • Great answer. Very useful since I'm fighting a similar design problem right now. :)

    – Dr. Mike
    Nov 10 '13 at 21:04











  • This should have been the selected answer. Very helpful, thanks!

    – dsignr
    Jul 15 '15 at 13:56











  • @Michael "You'll notice that answers links to question_options, not questions. This is intentional." Could you please provide further explanations on why ? :)

    – Pak
    Mar 3 '16 at 9:28











  • @Michael Hi, great answer! If you would have to be able to customize the CSS of some questions in a HTML page, how would you do it? I have create a CssFile property in my companies table but I need to be more specific in a question level. Thanks.

    – Patrick
    Aug 26 '18 at 16:37



















2














Take a look at this general idea:



enter image description here



(Only the most essential fields are included in the model above, for brevity.)



This model has the following characteristics:




  • A single question can be shared among multiple surveys (and single survey, of course, can contain multiple questions). The SURVEY_QUESTION is the "link" table that implements this M:N relationship.

  • The order of questions in the survey is determines by SURVEY_QUESTION.QUESTION_NO. Since {SURVEY_NO, QUESTION_NO} is an (alternate) key, denoted by U1 in the diagram above, no two questions can occupy the same "slot" in the same survey. Different surveys can have same questions in a different order.

  • Each question has a series of possible answers or "options". The visual order of options is determined by OPTION.OPTION_NO, and since it is in the PK, no two options can occupy the same "slot" under the same question.

  • Different users can provide different answers to the same question (and, of course, one user can answer multiple questions). This M:N relationship is implemented through the "link" table ANSWER.

  • A user answers the question by choosing at most one of its options. This is ensured by excluding the OPTION_NO from the ANSWER's PK. If you want to allow user to select multiple options, include OPTION_NO in the PK.


There is nothing in this data model that forces the user to answer all the questions - this is something you'll need to do at the application level. Nonetheless, this model should be a good start for what you need to do...






share|improve this answer
























  • I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 7:00



















1














You will need another table to hold the answers of users.




user_answers
------------
user_answer_id - unique primary key
user_id - FK to User table
chosen_option_id - FK to Option table
question_id - FK to Question table


If you decide you want users to be able to select "Other" as an option and fill in their own value, I'd recommend a separate table for that:




user_alt_answers
----------------
user_alt_answer_id - PK
alt_answer_text - text that the user entered for an "other" option.
user_answeR_id - FK to user_answers table





share|improve this answer
























  • I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 6:59



















0














[I can't comment yet, hence this as an answer]



For the solution VansFannel presented, I made a more complete model there.



Please, check it here.






share|improve this answer


























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f16002%2fsurvey-database-design-associate-an-answer-to-a-user%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7














    You need to make a distinction between the possible answers and the selected answers.



    The Option table needs to be two tables. The Option table should be 1:M to Question and should include the possible answers for that question.



    Then you need to make a new intersection entity, call it Selected_Option which sits between User and Option.



    If your question gives the user an opportunity to fill in a value as an answer (i.e. "OTHER:...") then this value would be stored in the Selected_Option table. Otherwise the value chosen by the user would be the value found in Option.





    EDIT:



    Based on OP's clarification of requirements: What you need is not like a typical questionnaire model in the following ways:




    • Your questions all have the same sets of answers (columns)

    • Some of your answers (columns) are grouped together.

    • Blocks of questions are grouped together.


    Taking your form snapshot as a guide, I've divided up the elements of your form into entities which I've colour coded:



    Colour Coded Form Example



    This could be accomodated by the following logical ERD:



    Logical ERD



    Note that I've colour coded the entities in the ERD to correspond to the snapshot of your sample form to show the correlation.



    One of the assumptions in this model is that each block has only one set of quesitons (i.e. one QUESTION_GROUP) which corresponds to the left-hand column in the block. This is a bit of a simplifying assumption.






    share|improve this answer


























    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 6:58






    • 1





      @VansFannel - I've updated my answer to reflect your edited question.

      – Joel Brown
      Apr 4 '12 at 12:24











    • Thank you very much! You have helped me a lot. I have added my final design as a question here: dba.stackexchange.com/questions/16066/… You can check it if you wish.

      – VansFannel
      Apr 4 '12 at 12:26













    • One question: What does it mean "sequence" and "value"? I haven't worked so much with ERD (sorry).

      – VansFannel
      Apr 4 '12 at 12:54











    • @VansFannel - The attribute notes in the ERD are just non-trivial (or non-obvious) columns in the tables. I expect that you'd guess where to put IDs, FKs, descriptions, etc. For sequence I'm suggesting that you'll need/want to control the order in which items are displayed. For value I'm pointing out that a user-entered value (not just an option selection) may be appropriate.

      – Joel Brown
      Apr 4 '12 at 19:30
















    7














    You need to make a distinction between the possible answers and the selected answers.



    The Option table needs to be two tables. The Option table should be 1:M to Question and should include the possible answers for that question.



    Then you need to make a new intersection entity, call it Selected_Option which sits between User and Option.



    If your question gives the user an opportunity to fill in a value as an answer (i.e. "OTHER:...") then this value would be stored in the Selected_Option table. Otherwise the value chosen by the user would be the value found in Option.





    EDIT:



    Based on OP's clarification of requirements: What you need is not like a typical questionnaire model in the following ways:




    • Your questions all have the same sets of answers (columns)

    • Some of your answers (columns) are grouped together.

    • Blocks of questions are grouped together.


    Taking your form snapshot as a guide, I've divided up the elements of your form into entities which I've colour coded:



    Colour Coded Form Example



    This could be accomodated by the following logical ERD:



    Logical ERD



    Note that I've colour coded the entities in the ERD to correspond to the snapshot of your sample form to show the correlation.



    One of the assumptions in this model is that each block has only one set of quesitons (i.e. one QUESTION_GROUP) which corresponds to the left-hand column in the block. This is a bit of a simplifying assumption.






    share|improve this answer


























    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 6:58






    • 1





      @VansFannel - I've updated my answer to reflect your edited question.

      – Joel Brown
      Apr 4 '12 at 12:24











    • Thank you very much! You have helped me a lot. I have added my final design as a question here: dba.stackexchange.com/questions/16066/… You can check it if you wish.

      – VansFannel
      Apr 4 '12 at 12:26













    • One question: What does it mean "sequence" and "value"? I haven't worked so much with ERD (sorry).

      – VansFannel
      Apr 4 '12 at 12:54











    • @VansFannel - The attribute notes in the ERD are just non-trivial (or non-obvious) columns in the tables. I expect that you'd guess where to put IDs, FKs, descriptions, etc. For sequence I'm suggesting that you'll need/want to control the order in which items are displayed. For value I'm pointing out that a user-entered value (not just an option selection) may be appropriate.

      – Joel Brown
      Apr 4 '12 at 19:30














    7












    7








    7







    You need to make a distinction between the possible answers and the selected answers.



    The Option table needs to be two tables. The Option table should be 1:M to Question and should include the possible answers for that question.



    Then you need to make a new intersection entity, call it Selected_Option which sits between User and Option.



    If your question gives the user an opportunity to fill in a value as an answer (i.e. "OTHER:...") then this value would be stored in the Selected_Option table. Otherwise the value chosen by the user would be the value found in Option.





    EDIT:



    Based on OP's clarification of requirements: What you need is not like a typical questionnaire model in the following ways:




    • Your questions all have the same sets of answers (columns)

    • Some of your answers (columns) are grouped together.

    • Blocks of questions are grouped together.


    Taking your form snapshot as a guide, I've divided up the elements of your form into entities which I've colour coded:



    Colour Coded Form Example



    This could be accomodated by the following logical ERD:



    Logical ERD



    Note that I've colour coded the entities in the ERD to correspond to the snapshot of your sample form to show the correlation.



    One of the assumptions in this model is that each block has only one set of quesitons (i.e. one QUESTION_GROUP) which corresponds to the left-hand column in the block. This is a bit of a simplifying assumption.






    share|improve this answer















    You need to make a distinction between the possible answers and the selected answers.



    The Option table needs to be two tables. The Option table should be 1:M to Question and should include the possible answers for that question.



    Then you need to make a new intersection entity, call it Selected_Option which sits between User and Option.



    If your question gives the user an opportunity to fill in a value as an answer (i.e. "OTHER:...") then this value would be stored in the Selected_Option table. Otherwise the value chosen by the user would be the value found in Option.





    EDIT:



    Based on OP's clarification of requirements: What you need is not like a typical questionnaire model in the following ways:




    • Your questions all have the same sets of answers (columns)

    • Some of your answers (columns) are grouped together.

    • Blocks of questions are grouped together.


    Taking your form snapshot as a guide, I've divided up the elements of your form into entities which I've colour coded:



    Colour Coded Form Example



    This could be accomodated by the following logical ERD:



    Logical ERD



    Note that I've colour coded the entities in the ERD to correspond to the snapshot of your sample form to show the correlation.



    One of the assumptions in this model is that each block has only one set of quesitons (i.e. one QUESTION_GROUP) which corresponds to the left-hand column in the block. This is a bit of a simplifying assumption.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 4 '12 at 12:24

























    answered Apr 3 '12 at 13:11









    Joel BrownJoel Brown

    10.5k21837




    10.5k21837













    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 6:58






    • 1





      @VansFannel - I've updated my answer to reflect your edited question.

      – Joel Brown
      Apr 4 '12 at 12:24











    • Thank you very much! You have helped me a lot. I have added my final design as a question here: dba.stackexchange.com/questions/16066/… You can check it if you wish.

      – VansFannel
      Apr 4 '12 at 12:26













    • One question: What does it mean "sequence" and "value"? I haven't worked so much with ERD (sorry).

      – VansFannel
      Apr 4 '12 at 12:54











    • @VansFannel - The attribute notes in the ERD are just non-trivial (or non-obvious) columns in the tables. I expect that you'd guess where to put IDs, FKs, descriptions, etc. For sequence I'm suggesting that you'll need/want to control the order in which items are displayed. For value I'm pointing out that a user-entered value (not just an option selection) may be appropriate.

      – Joel Brown
      Apr 4 '12 at 19:30



















    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 6:58






    • 1





      @VansFannel - I've updated my answer to reflect your edited question.

      – Joel Brown
      Apr 4 '12 at 12:24











    • Thank you very much! You have helped me a lot. I have added my final design as a question here: dba.stackexchange.com/questions/16066/… You can check it if you wish.

      – VansFannel
      Apr 4 '12 at 12:26













    • One question: What does it mean "sequence" and "value"? I haven't worked so much with ERD (sorry).

      – VansFannel
      Apr 4 '12 at 12:54











    • @VansFannel - The attribute notes in the ERD are just non-trivial (or non-obvious) columns in the tables. I expect that you'd guess where to put IDs, FKs, descriptions, etc. For sequence I'm suggesting that you'll need/want to control the order in which items are displayed. For value I'm pointing out that a user-entered value (not just an option selection) may be appropriate.

      – Joel Brown
      Apr 4 '12 at 19:30

















    I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 6:58





    I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 6:58




    1




    1





    @VansFannel - I've updated my answer to reflect your edited question.

    – Joel Brown
    Apr 4 '12 at 12:24





    @VansFannel - I've updated my answer to reflect your edited question.

    – Joel Brown
    Apr 4 '12 at 12:24













    Thank you very much! You have helped me a lot. I have added my final design as a question here: dba.stackexchange.com/questions/16066/… You can check it if you wish.

    – VansFannel
    Apr 4 '12 at 12:26







    Thank you very much! You have helped me a lot. I have added my final design as a question here: dba.stackexchange.com/questions/16066/… You can check it if you wish.

    – VansFannel
    Apr 4 '12 at 12:26















    One question: What does it mean "sequence" and "value"? I haven't worked so much with ERD (sorry).

    – VansFannel
    Apr 4 '12 at 12:54





    One question: What does it mean "sequence" and "value"? I haven't worked so much with ERD (sorry).

    – VansFannel
    Apr 4 '12 at 12:54













    @VansFannel - The attribute notes in the ERD are just non-trivial (or non-obvious) columns in the tables. I expect that you'd guess where to put IDs, FKs, descriptions, etc. For sequence I'm suggesting that you'll need/want to control the order in which items are displayed. For value I'm pointing out that a user-entered value (not just an option selection) may be appropriate.

    – Joel Brown
    Apr 4 '12 at 19:30





    @VansFannel - The attribute notes in the ERD are just non-trivial (or non-obvious) columns in the tables. I expect that you'd guess where to put IDs, FKs, descriptions, etc. For sequence I'm suggesting that you'll need/want to control the order in which items are displayed. For value I'm pointing out that a user-entered value (not just an option selection) may be appropriate.

    – Joel Brown
    Apr 4 '12 at 19:30













    12














    This is a real classic, done by thousands. They always seems 'fairly simple' to start with but to be good it's actually pretty complex. To do this in Rails I would use the model shown in the attached diagram. I'm sure it seems way over complicated for some, but once you've built a few of these, over the years, you realize that most of the design decisions are very classic patterns, best addressed by a dynamic flexible data structure at the outset.

    More details below:



    enter image description here




    Table details for key tables




    answers



    The answers table is critical as it captures the actual responses by users.
    You'll notice that answers links to question_options, not questions. This is intentional.



    input_types



    input_types are the types of questions. Each question can only be of 1 type, e.g. all radio dials, all text field(s), etc. Use additional questions for when there are (say) 5 radio-dials and 1 check box for an "include?" option or some such combination. Label the two questions in the users view as one but internally have two questions, one for the radio-dials, one for the check box. The checkbox will have a group of 1 in this case.



    option_groups



    option_groups and option_choices let you build 'common' groups.
    One example, in a real estate application there might be the question 'How old is the property?'.
    The answers might be desired in the ranges:
    1-5
    6-10
    10-25
    25-100
    100+



    Then, for example, if there is a question about the adjoining property age, then the survey will want to 'reuse' the above ranges, so that same option_group and options get used.



    units_of_measure



    units_of_measure is as it sounds. Whether it's inches, cups, pixels, bricks or whatever, you can define it once here.



    FYI: Although generic in nature, one can create an application on top of this, and this schema is well-suited to the Ruby On Rails framework with conventions such as "id" for the primary key for each table. Also the relationships are all simple one_to_many's with no many_to_many or has_many throughs needed. I would probably add has_many :throughs and/or :delegates though to get things like survey_name from an individual answer easily without.multiple.chaining.






    share|improve this answer
























    • Great! Thanks for your answer. I will learn a lot with it. Thank you.

      – VansFannel
      Apr 21 '12 at 14:19











    • Great answer. Very useful since I'm fighting a similar design problem right now. :)

      – Dr. Mike
      Nov 10 '13 at 21:04











    • This should have been the selected answer. Very helpful, thanks!

      – dsignr
      Jul 15 '15 at 13:56











    • @Michael "You'll notice that answers links to question_options, not questions. This is intentional." Could you please provide further explanations on why ? :)

      – Pak
      Mar 3 '16 at 9:28











    • @Michael Hi, great answer! If you would have to be able to customize the CSS of some questions in a HTML page, how would you do it? I have create a CssFile property in my companies table but I need to be more specific in a question level. Thanks.

      – Patrick
      Aug 26 '18 at 16:37
















    12














    This is a real classic, done by thousands. They always seems 'fairly simple' to start with but to be good it's actually pretty complex. To do this in Rails I would use the model shown in the attached diagram. I'm sure it seems way over complicated for some, but once you've built a few of these, over the years, you realize that most of the design decisions are very classic patterns, best addressed by a dynamic flexible data structure at the outset.

    More details below:



    enter image description here




    Table details for key tables




    answers



    The answers table is critical as it captures the actual responses by users.
    You'll notice that answers links to question_options, not questions. This is intentional.



    input_types



    input_types are the types of questions. Each question can only be of 1 type, e.g. all radio dials, all text field(s), etc. Use additional questions for when there are (say) 5 radio-dials and 1 check box for an "include?" option or some such combination. Label the two questions in the users view as one but internally have two questions, one for the radio-dials, one for the check box. The checkbox will have a group of 1 in this case.



    option_groups



    option_groups and option_choices let you build 'common' groups.
    One example, in a real estate application there might be the question 'How old is the property?'.
    The answers might be desired in the ranges:
    1-5
    6-10
    10-25
    25-100
    100+



    Then, for example, if there is a question about the adjoining property age, then the survey will want to 'reuse' the above ranges, so that same option_group and options get used.



    units_of_measure



    units_of_measure is as it sounds. Whether it's inches, cups, pixels, bricks or whatever, you can define it once here.



    FYI: Although generic in nature, one can create an application on top of this, and this schema is well-suited to the Ruby On Rails framework with conventions such as "id" for the primary key for each table. Also the relationships are all simple one_to_many's with no many_to_many or has_many throughs needed. I would probably add has_many :throughs and/or :delegates though to get things like survey_name from an individual answer easily without.multiple.chaining.






    share|improve this answer
























    • Great! Thanks for your answer. I will learn a lot with it. Thank you.

      – VansFannel
      Apr 21 '12 at 14:19











    • Great answer. Very useful since I'm fighting a similar design problem right now. :)

      – Dr. Mike
      Nov 10 '13 at 21:04











    • This should have been the selected answer. Very helpful, thanks!

      – dsignr
      Jul 15 '15 at 13:56











    • @Michael "You'll notice that answers links to question_options, not questions. This is intentional." Could you please provide further explanations on why ? :)

      – Pak
      Mar 3 '16 at 9:28











    • @Michael Hi, great answer! If you would have to be able to customize the CSS of some questions in a HTML page, how would you do it? I have create a CssFile property in my companies table but I need to be more specific in a question level. Thanks.

      – Patrick
      Aug 26 '18 at 16:37














    12












    12








    12







    This is a real classic, done by thousands. They always seems 'fairly simple' to start with but to be good it's actually pretty complex. To do this in Rails I would use the model shown in the attached diagram. I'm sure it seems way over complicated for some, but once you've built a few of these, over the years, you realize that most of the design decisions are very classic patterns, best addressed by a dynamic flexible data structure at the outset.

    More details below:



    enter image description here




    Table details for key tables




    answers



    The answers table is critical as it captures the actual responses by users.
    You'll notice that answers links to question_options, not questions. This is intentional.



    input_types



    input_types are the types of questions. Each question can only be of 1 type, e.g. all radio dials, all text field(s), etc. Use additional questions for when there are (say) 5 radio-dials and 1 check box for an "include?" option or some such combination. Label the two questions in the users view as one but internally have two questions, one for the radio-dials, one for the check box. The checkbox will have a group of 1 in this case.



    option_groups



    option_groups and option_choices let you build 'common' groups.
    One example, in a real estate application there might be the question 'How old is the property?'.
    The answers might be desired in the ranges:
    1-5
    6-10
    10-25
    25-100
    100+



    Then, for example, if there is a question about the adjoining property age, then the survey will want to 'reuse' the above ranges, so that same option_group and options get used.



    units_of_measure



    units_of_measure is as it sounds. Whether it's inches, cups, pixels, bricks or whatever, you can define it once here.



    FYI: Although generic in nature, one can create an application on top of this, and this schema is well-suited to the Ruby On Rails framework with conventions such as "id" for the primary key for each table. Also the relationships are all simple one_to_many's with no many_to_many or has_many throughs needed. I would probably add has_many :throughs and/or :delegates though to get things like survey_name from an individual answer easily without.multiple.chaining.






    share|improve this answer













    This is a real classic, done by thousands. They always seems 'fairly simple' to start with but to be good it's actually pretty complex. To do this in Rails I would use the model shown in the attached diagram. I'm sure it seems way over complicated for some, but once you've built a few of these, over the years, you realize that most of the design decisions are very classic patterns, best addressed by a dynamic flexible data structure at the outset.

    More details below:



    enter image description here




    Table details for key tables




    answers



    The answers table is critical as it captures the actual responses by users.
    You'll notice that answers links to question_options, not questions. This is intentional.



    input_types



    input_types are the types of questions. Each question can only be of 1 type, e.g. all radio dials, all text field(s), etc. Use additional questions for when there are (say) 5 radio-dials and 1 check box for an "include?" option or some such combination. Label the two questions in the users view as one but internally have two questions, one for the radio-dials, one for the check box. The checkbox will have a group of 1 in this case.



    option_groups



    option_groups and option_choices let you build 'common' groups.
    One example, in a real estate application there might be the question 'How old is the property?'.
    The answers might be desired in the ranges:
    1-5
    6-10
    10-25
    25-100
    100+



    Then, for example, if there is a question about the adjoining property age, then the survey will want to 'reuse' the above ranges, so that same option_group and options get used.



    units_of_measure



    units_of_measure is as it sounds. Whether it's inches, cups, pixels, bricks or whatever, you can define it once here.



    FYI: Although generic in nature, one can create an application on top of this, and this schema is well-suited to the Ruby On Rails framework with conventions such as "id" for the primary key for each table. Also the relationships are all simple one_to_many's with no many_to_many or has_many throughs needed. I would probably add has_many :throughs and/or :delegates though to get things like survey_name from an individual answer easily without.multiple.chaining.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 21 '12 at 13:23









    Michael DurrantMichael Durrant

    4901411




    4901411













    • Great! Thanks for your answer. I will learn a lot with it. Thank you.

      – VansFannel
      Apr 21 '12 at 14:19











    • Great answer. Very useful since I'm fighting a similar design problem right now. :)

      – Dr. Mike
      Nov 10 '13 at 21:04











    • This should have been the selected answer. Very helpful, thanks!

      – dsignr
      Jul 15 '15 at 13:56











    • @Michael "You'll notice that answers links to question_options, not questions. This is intentional." Could you please provide further explanations on why ? :)

      – Pak
      Mar 3 '16 at 9:28











    • @Michael Hi, great answer! If you would have to be able to customize the CSS of some questions in a HTML page, how would you do it? I have create a CssFile property in my companies table but I need to be more specific in a question level. Thanks.

      – Patrick
      Aug 26 '18 at 16:37



















    • Great! Thanks for your answer. I will learn a lot with it. Thank you.

      – VansFannel
      Apr 21 '12 at 14:19











    • Great answer. Very useful since I'm fighting a similar design problem right now. :)

      – Dr. Mike
      Nov 10 '13 at 21:04











    • This should have been the selected answer. Very helpful, thanks!

      – dsignr
      Jul 15 '15 at 13:56











    • @Michael "You'll notice that answers links to question_options, not questions. This is intentional." Could you please provide further explanations on why ? :)

      – Pak
      Mar 3 '16 at 9:28











    • @Michael Hi, great answer! If you would have to be able to customize the CSS of some questions in a HTML page, how would you do it? I have create a CssFile property in my companies table but I need to be more specific in a question level. Thanks.

      – Patrick
      Aug 26 '18 at 16:37

















    Great! Thanks for your answer. I will learn a lot with it. Thank you.

    – VansFannel
    Apr 21 '12 at 14:19





    Great! Thanks for your answer. I will learn a lot with it. Thank you.

    – VansFannel
    Apr 21 '12 at 14:19













    Great answer. Very useful since I'm fighting a similar design problem right now. :)

    – Dr. Mike
    Nov 10 '13 at 21:04





    Great answer. Very useful since I'm fighting a similar design problem right now. :)

    – Dr. Mike
    Nov 10 '13 at 21:04













    This should have been the selected answer. Very helpful, thanks!

    – dsignr
    Jul 15 '15 at 13:56





    This should have been the selected answer. Very helpful, thanks!

    – dsignr
    Jul 15 '15 at 13:56













    @Michael "You'll notice that answers links to question_options, not questions. This is intentional." Could you please provide further explanations on why ? :)

    – Pak
    Mar 3 '16 at 9:28





    @Michael "You'll notice that answers links to question_options, not questions. This is intentional." Could you please provide further explanations on why ? :)

    – Pak
    Mar 3 '16 at 9:28













    @Michael Hi, great answer! If you would have to be able to customize the CSS of some questions in a HTML page, how would you do it? I have create a CssFile property in my companies table but I need to be more specific in a question level. Thanks.

    – Patrick
    Aug 26 '18 at 16:37





    @Michael Hi, great answer! If you would have to be able to customize the CSS of some questions in a HTML page, how would you do it? I have create a CssFile property in my companies table but I need to be more specific in a question level. Thanks.

    – Patrick
    Aug 26 '18 at 16:37











    2














    Take a look at this general idea:



    enter image description here



    (Only the most essential fields are included in the model above, for brevity.)



    This model has the following characteristics:




    • A single question can be shared among multiple surveys (and single survey, of course, can contain multiple questions). The SURVEY_QUESTION is the "link" table that implements this M:N relationship.

    • The order of questions in the survey is determines by SURVEY_QUESTION.QUESTION_NO. Since {SURVEY_NO, QUESTION_NO} is an (alternate) key, denoted by U1 in the diagram above, no two questions can occupy the same "slot" in the same survey. Different surveys can have same questions in a different order.

    • Each question has a series of possible answers or "options". The visual order of options is determined by OPTION.OPTION_NO, and since it is in the PK, no two options can occupy the same "slot" under the same question.

    • Different users can provide different answers to the same question (and, of course, one user can answer multiple questions). This M:N relationship is implemented through the "link" table ANSWER.

    • A user answers the question by choosing at most one of its options. This is ensured by excluding the OPTION_NO from the ANSWER's PK. If you want to allow user to select multiple options, include OPTION_NO in the PK.


    There is nothing in this data model that forces the user to answer all the questions - this is something you'll need to do at the application level. Nonetheless, this model should be a good start for what you need to do...






    share|improve this answer
























    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 7:00
















    2














    Take a look at this general idea:



    enter image description here



    (Only the most essential fields are included in the model above, for brevity.)



    This model has the following characteristics:




    • A single question can be shared among multiple surveys (and single survey, of course, can contain multiple questions). The SURVEY_QUESTION is the "link" table that implements this M:N relationship.

    • The order of questions in the survey is determines by SURVEY_QUESTION.QUESTION_NO. Since {SURVEY_NO, QUESTION_NO} is an (alternate) key, denoted by U1 in the diagram above, no two questions can occupy the same "slot" in the same survey. Different surveys can have same questions in a different order.

    • Each question has a series of possible answers or "options". The visual order of options is determined by OPTION.OPTION_NO, and since it is in the PK, no two options can occupy the same "slot" under the same question.

    • Different users can provide different answers to the same question (and, of course, one user can answer multiple questions). This M:N relationship is implemented through the "link" table ANSWER.

    • A user answers the question by choosing at most one of its options. This is ensured by excluding the OPTION_NO from the ANSWER's PK. If you want to allow user to select multiple options, include OPTION_NO in the PK.


    There is nothing in this data model that forces the user to answer all the questions - this is something you'll need to do at the application level. Nonetheless, this model should be a good start for what you need to do...






    share|improve this answer
























    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 7:00














    2












    2








    2







    Take a look at this general idea:



    enter image description here



    (Only the most essential fields are included in the model above, for brevity.)



    This model has the following characteristics:




    • A single question can be shared among multiple surveys (and single survey, of course, can contain multiple questions). The SURVEY_QUESTION is the "link" table that implements this M:N relationship.

    • The order of questions in the survey is determines by SURVEY_QUESTION.QUESTION_NO. Since {SURVEY_NO, QUESTION_NO} is an (alternate) key, denoted by U1 in the diagram above, no two questions can occupy the same "slot" in the same survey. Different surveys can have same questions in a different order.

    • Each question has a series of possible answers or "options". The visual order of options is determined by OPTION.OPTION_NO, and since it is in the PK, no two options can occupy the same "slot" under the same question.

    • Different users can provide different answers to the same question (and, of course, one user can answer multiple questions). This M:N relationship is implemented through the "link" table ANSWER.

    • A user answers the question by choosing at most one of its options. This is ensured by excluding the OPTION_NO from the ANSWER's PK. If you want to allow user to select multiple options, include OPTION_NO in the PK.


    There is nothing in this data model that forces the user to answer all the questions - this is something you'll need to do at the application level. Nonetheless, this model should be a good start for what you need to do...






    share|improve this answer













    Take a look at this general idea:



    enter image description here



    (Only the most essential fields are included in the model above, for brevity.)



    This model has the following characteristics:




    • A single question can be shared among multiple surveys (and single survey, of course, can contain multiple questions). The SURVEY_QUESTION is the "link" table that implements this M:N relationship.

    • The order of questions in the survey is determines by SURVEY_QUESTION.QUESTION_NO. Since {SURVEY_NO, QUESTION_NO} is an (alternate) key, denoted by U1 in the diagram above, no two questions can occupy the same "slot" in the same survey. Different surveys can have same questions in a different order.

    • Each question has a series of possible answers or "options". The visual order of options is determined by OPTION.OPTION_NO, and since it is in the PK, no two options can occupy the same "slot" under the same question.

    • Different users can provide different answers to the same question (and, of course, one user can answer multiple questions). This M:N relationship is implemented through the "link" table ANSWER.

    • A user answers the question by choosing at most one of its options. This is ensured by excluding the OPTION_NO from the ANSWER's PK. If you want to allow user to select multiple options, include OPTION_NO in the PK.


    There is nothing in this data model that forces the user to answer all the questions - this is something you'll need to do at the application level. Nonetheless, this model should be a good start for what you need to do...







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 4 '12 at 0:20









    Branko DimitrijevicBranko Dimitrijevic

    570411




    570411













    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 7:00



















    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 7:00

















    I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 7:00





    I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 7:00











    1














    You will need another table to hold the answers of users.




    user_answers
    ------------
    user_answer_id - unique primary key
    user_id - FK to User table
    chosen_option_id - FK to Option table
    question_id - FK to Question table


    If you decide you want users to be able to select "Other" as an option and fill in their own value, I'd recommend a separate table for that:




    user_alt_answers
    ----------------
    user_alt_answer_id - PK
    alt_answer_text - text that the user entered for an "other" option.
    user_answeR_id - FK to user_answers table





    share|improve this answer
























    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 6:59
















    1














    You will need another table to hold the answers of users.




    user_answers
    ------------
    user_answer_id - unique primary key
    user_id - FK to User table
    chosen_option_id - FK to Option table
    question_id - FK to Question table


    If you decide you want users to be able to select "Other" as an option and fill in their own value, I'd recommend a separate table for that:




    user_alt_answers
    ----------------
    user_alt_answer_id - PK
    alt_answer_text - text that the user entered for an "other" option.
    user_answeR_id - FK to user_answers table





    share|improve this answer
























    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 6:59














    1












    1








    1







    You will need another table to hold the answers of users.




    user_answers
    ------------
    user_answer_id - unique primary key
    user_id - FK to User table
    chosen_option_id - FK to Option table
    question_id - FK to Question table


    If you decide you want users to be able to select "Other" as an option and fill in their own value, I'd recommend a separate table for that:




    user_alt_answers
    ----------------
    user_alt_answer_id - PK
    alt_answer_text - text that the user entered for an "other" option.
    user_answeR_id - FK to user_answers table





    share|improve this answer













    You will need another table to hold the answers of users.




    user_answers
    ------------
    user_answer_id - unique primary key
    user_id - FK to User table
    chosen_option_id - FK to Option table
    question_id - FK to Question table


    If you decide you want users to be able to select "Other" as an option and fill in their own value, I'd recommend a separate table for that:




    user_alt_answers
    ----------------
    user_alt_answer_id - PK
    alt_answer_text - text that the user entered for an "other" option.
    user_answeR_id - FK to user_answers table






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 3 '12 at 14:34









    FrustratedWithFormsDesignerFrustratedWithFormsDesigner

    3,1321318




    3,1321318













    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 6:59



















    • I have updated my question with an image of a tipical survey question.

      – VansFannel
      Apr 4 '12 at 6:59

















    I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 6:59





    I have updated my question with an image of a tipical survey question.

    – VansFannel
    Apr 4 '12 at 6:59











    0














    [I can't comment yet, hence this as an answer]



    For the solution VansFannel presented, I made a more complete model there.



    Please, check it here.






    share|improve this answer






























      0














      [I can't comment yet, hence this as an answer]



      For the solution VansFannel presented, I made a more complete model there.



      Please, check it here.






      share|improve this answer




























        0












        0








        0







        [I can't comment yet, hence this as an answer]



        For the solution VansFannel presented, I made a more complete model there.



        Please, check it here.






        share|improve this answer















        [I can't comment yet, hence this as an answer]



        For the solution VansFannel presented, I made a more complete model there.



        Please, check it here.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 13 '17 at 12:42









        Community

        1




        1










        answered Sep 26 '12 at 3:44









        Marcus Vinicius PompeuMarcus Vinicius Pompeu

        52629




        52629






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f16002%2fsurvey-database-design-associate-an-answer-to-a-user%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            ORA-01691 (unable to extend lob segment) even though my tablespace has AUTOEXTEND onORA-01692: unable to...

            Always On Availability groups resolving state after failover - Remote harden of transaction...

            Circunscripción electoral de Guipúzcoa Referencias Menú de navegaciónLas claves del sistema electoral en...