what should be database schema for online voting app - database

I want to develop an app where Events/Question would be posted by admin and user will vote or answer. Here question can be of three different type and each type can have different option.Admin can view reports about each question
E.g
WHQuestion: What is right age for marriage? (1) >20 (2)=20 (3)20<
Voting:Who is best captain (1)ABC (2)PQR n so on......
YesNoQuestion: Is Dhoni a good captain? (1)Yes (2)No
So I am confused here about the database schema and tables. How should i manage them?

All questions are multiple choice with one or zero correct answers. So: One question, some answers, one optional correct answer.
Question: question_no, text
Answer: question_no, answer_no, text
As to how to store which answer per question is correct, there are two options:
Store the answer_no in the question record. I consider this the better option. A dbms featuring deferred Constraints (so a question record can reference an answer record and vice versa) would be a good thing to have here. If there is no correct answer the answer_no is null.
Have a flag in the answers table and then mark one answer per question as correct and the others as incorrect. This would be appropriate if there were multiple correct answers per question possible. For one correct answer, however, this would be the worse option of the two. To guarantee data consistency you would apply some special check, which can be a bit complicated (for instance a function index to guarantee uniqueness). For no correct answer you could store the same value or even null for all answers. However, you must see the answers to find out that this is a vote question. So again, option 1 is the better choice where you see this immediately in the question record.

Related

Deal with Many Choice and Matching Questions in Testing Schema

Struggling to find a way to allow many choice questions and matching questions in my testing schema. I'm guessing I should have a column in the QUESTIONS_LINK table denoting the amount of correct answers for that question. For matching, I just have no clue how to logically relate the somewhat "unrelated" options with the answers for each so that it can be grabbed to be displayed on the web page. Note: strong/weak relationship lines may not be accurate.

Database Design for Conditional Questionnaire

I am designing a database schema to support a business case in which a user can submit a request (for him/herself or on someone else's behalf). To process and complete the request, the submitter will be prompted with questions based on their answers to prior questions. That is to say, the next question is conditional based on the current question's answer.
Each question will have an associated type, which will drive the user form for that particular question. A question of type boolean indicates Yes/No radio buttons for the answer. Questions of type multiple indicates a multiple choice answer, where users will select one of multiple radio options.
I have two questions:
How can I modify my schema to "link" answers to multiple choice questions? (ie "the following answers are available for question X.")
How should the answers drive the next question? (ie. "for question #1, if answer A is chosen, then GOTO question 5")
My question_relationships table will let me specify that question 1 is the parent of question 5, and question 5 is the parent of question 6. But I really need the answers to drive this logic.
question
-id
-question_name
-question_text
-question_hint
-question_type (boolean, multiple)
question_relationship
-id
-fk_parent_question_id
-fk_child_question_id
request
-id
-person_id
-submitter_id
-submit_date
-status
request_answer
-id
-fk_request_id
-fk_question_id
-answer_text
-answer_boolean
I have seen the answers in db design - survey/quiz with questions and answers, but I believe that my scenario is a bit different.
A table has an associated fill-in-the-(named-)blanks statement aka predicate. Rows that make it into a true statement go in the table. Rows that make it into a false statement stay out. That's how we interpret a table (base, view or query) and update a base. Each table represents an application relationship.
(So your predicate-style quote for 2 is how to give a table's meaning. Because then JOIN's meaning is the AND of argument meanings, and UNION the OR, EXCEPT is the AND NOT, etc.)
How can I modify my schema to "link" answers to multiple choice
questions? (ie "the following answers are available for question X.")
// question [question_id] has available answer [answer_id]
question_answers(question_id, answerid)
How should the answers drive the next question?
(ie. "for question #1, if answer A is chosen, then GOTO question 5")
// for question [this_id] if answer [answer_id] is chosen then go to question [next_id]
next_question(this_id, answer_id, next_id)
PS
There are many different ways of representing graphs (nodes with edges between them) via tables. Here the nodes are questions and the edges are this-next question pairs. Different tables support different kinds of graphs and different patterns of reading and update. (I chose one reflecting your application, but framed my answer to help you find your best representation via proper design yourself.)
PPS
If different user traces through questions can mean that which question follows another is context-dependent:
// in context [this_id] if answer [answer_id] is chosen then go to context[next_id]
next_context(this_id, answer_id, next_id)
What a "context" is depends on aspects of your application that you have not given. What you have given suggests that your only notion of context is the current question. Also, depending on what a context contains, this table may need normalization. You might want independent notions of current context vs current question. (Topic: finite state machines.)

Is there a way to store array like data in a column in SQL Server?

I have a table that holds Test Questions. Each row of the table contains details of a question for a test for a particular user.
The user is presented with 3-5 possible answers and I would like to store details of the answers that have been checked in the row. I don't really want to add new rows for every answer as this would create a huge number of rows.
Is there a way that I can store something like an array of answers in a column in SQL Server? Presently I am storing the data as a JSON string but I remember that Oracle had some way to store array data and I am wondering if SQL Server has the same.
Generally denormallizing is not a good idea. It is rarely a good idea idea. However, it is sometimes necessary for performance reasons. So, if not too slow, don't even consider it.
If you make a secondary answers table in your case with the TestQuestionID (or whatever you call the answers for a single question) to be the clustered index, it won't be much of a performance difference at all compared to a denormalized table.
If I were denormalizing your descriibed table I would probably just create 5 columns in the table, You could also use an xml field, but all you are storing is 5 answers, so I would not use xml in this simple case.
Since you are asking this question, you are not really a seasoned professional (we all start as novices) and you should consult the local sql expert before you denormalize.
ADDED CAVEAT,
Since you accepted this answer, you really need to understand for certain that denormalizing is almost always the wrong thing to do. That is why everyone, including me, was trying to tell you. Don't do this without talking to your DBA -- if you don't have a local DBA (unfortunately all too common) take the collective advice, and don't denormalize. I can think of only 1 time n my career that I think denormalizing was the correct solution. And I have bitten by the bad design (forced on me) by innappropriate denormlazation on many occasions.

Logic for recommender application

I am developing an application - which would have users answer maybe 10 questions - which would have 3-4 options for each question. At the end of the 10th question, based on the responses, it would need to suggest a certain solution. Since there are 100's of permutation and combinations - what's the logic that would be required to use and the database design,
thanks
EDIT some more detailed explanation
if my application is used to recommend a data plan from various mobile operators - based on the user answering questions like the time spent on the internet, the type of files being downloaded and so on. So, if the response to question 1 was a and question 2 was c, etc - then it would be a certain plan. If the response to question 1 was b and for question 2 it was c, then it would recommend a certain plan. So, if there were 10 questions - then the combinations can be quite large. So is there a certain algorithm that can handle this?
I. what would be the logic?
If I understand correctly, you would define "rules" such as
If the answer to question 5. is either A or B then the suggested plan would be planB, otherwise execute the rest of the rules.
So you would use a rule engine e.g.: http://www.jboss.org/drools/
II. what would be the database design?
This is quite simple:
USERS table,
QUESTIONS table and
ANSWERS table which would refer to the two others
Possibly there would be a QUESTIONNAIRE table as well, and the QUESTIONS table would refer to it.
Just a 'quick' comment, consider letting the user see changes in what company they could be recommended as they answer every question.
For example, if I am most interested in price that would be the question I would answer first and immediately see the 3 cheapest plans/products recommended to me.
The second question could be coverage and if I then could see the 3 plans with best coverage (in my area) that would be interesting too.
When I answer the third question about smart phone features and I say I want internet, then the first question should spit out the 3 cheapest plans/products that include internet, obviously they could change.
And so on...
Maybe it also could be a good idea to let the user "dive into" each question and see the full range of options for that answer. As a user I would appreciate that.
Above comments is just how I would appreciate if a form was made for me, I don't want to answer 10 questions about stuff I'm not really putting any value on, each user is different and will prefer to make their choice on their questions.
So, based on above it would be like a check list where the top answers would be the plans/products with the most fitting check marks. And to give immediate responses (as the user answer/alter each question), here AJAX would probably be your choice.

Q&A database map like stackoverflow - seperate table for questions titles

I am planning to make Q&A system (quite specific, has nothing to do with IT)
I was looking for Stackoverflow database map: https://meta.stackexchange.com/questions/2677/anatomy-of-a-data-dump/2678#2678
And I am thinking is not it is better practice to make separate table for questions titles. With "firstPostId".
Instead of
|- PostTypeId
| - 1: Question
| - 2: Answer
So I want to know, why stackoverflow did not use separate table for questions title. Is it "Do not optimize yet" or does it have any logic behind it?
Based just on the schema as shown in your link, I surmise that Questions and Answers have so many attributes in common that it was convenient to model it as was done. In short, symmetry and failing to multiply entities unnecessarily seem credible reasons for the approach.
I also suspect they use a key/value (a.k.a. nosql) database for the backing store which allows entries to not possess all possible attributes. For example, a question can have tags but an answer will not. Key/value databases don't fret over differences like that.
Disclaimer: I have no actual knowledge of how SO is implemented.

Resources