Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:54:46+00:00 2026-06-01T12:54:46+00:00

I am trying to implement a multiple choice quiz and will want to store

  • 0

I am trying to implement a multiple choice quiz and will want to store all my questions and answers in a SQLite database. I will have many questions, and for each question there will 2 or more possible answers to display.

My question is, how should I store the questions and answers in a database? I have two ideas for a schema (primary key in bold)

  1. as (many to many)

questions (questionID:int , questionString:String, correctAnswerID:int)

answers (answerID:int , answerString:String)

questions_and_answers (questionID, answerID)

2.

questions (questionID:int, questionString:String, correctAnswerID:int)

answers (answerID:int, answerString:String, questionID:int foreign key)

I’m not sure which one is better, or if there is another way?

Maybe questions_and_answers would get very large and cause long retrieval times and memory problems? Then again, I assume question_and_answers would be indexed on the primary keys. In the second schema, answers would be indexed on answerID and not questionID? meaning the search times would go up as the whole table would have to be searched?

There may be ~10,000 – 20,000 answers. (the quiz may be run on a mobile device and questions will need to be shown “instantly”)

Note: I don’t expect there to much overlap of answers between questions. I wouldn’t think the amount of overlap would mean less data being stored, considering the extra space required by the questions_and_answers table

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:54:48+00:00Added an answer on June 1, 2026 at 12:54 pm

    You’re second schema is the better one, because it models the actual domain: each question has a set of answers. Even if you can “compress” the data by storing duplicate answers once, it does not match the actual domain.

    Down the road you’ll want to edit answers. With schema 1, that means first searching if that answer already exists. If it does exist, you then would have to check if any questions still rely on the old answer. If it did not exist, you would still have to check if any other questions relied on that answer, and then either edit that answer in place or create a new answer.

    Schema 1 just makes life really hard.

    To answer your index questions, you would need to add an index on questionId. Once you have that index, looking up answers for a question should scale.

    Now, on a completely different note, why use a database for this? Consider storing them as simple documents in a standard format like json. Anytime you query a question, you will almost always want the answers, and vice versa. Instead of executing multiple queries, you can load the entire document in one step.

    If you then find you need more advanced storage (queries, redundancy, etc) you can move to a document database like MongoDB or CouchDB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
I'm trying to implement thinking-sphinx across multiple 'sites' hosted under a single rails application.
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all
I'm trying to implement an algorithm to search multiple XML files for a certain
I'm trying to implement a SessionState server to allow multiple web servers to share
I am trying to implement row moving in a DataGridView. I want to be
I'm trying to implement multiple spinners within one activity, which appears to be working
I'm really novice with ActionScript and Flash/Flex. I'm trying to implement a multiple file
I'm trying to implement a server-client socket program in Java that can support multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.