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 7406565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:34:40+00:00 2026-05-29T05:34:40+00:00

I may lack the mathematical background to find the right answer for myself. I

  • 0

I may lack the mathematical background to find the right answer for myself. I have tables set up like so (irrelevant columns omitted):

Questions
   queID

Answers
   queID
   ansID

Users can create quizzes by picking certain questions. Answers are the possible answers users can choose from per question.

Sessions
   sessID

When a customer picks a group of questions to answer, a “Session” is created.

SessionQuestions
   sqID
   sessID
   queID

These are the questions a user selected for a given session.

Where I’m hitting a snag is at the SessionAnswers level. The order of answers for a question can be random. That is, a multiple-choice question with default answer order of A,B,C can be displayed as C,B,A to a user. Whenever they view that question again, though, it still needs to be C,B,A, so that final order needs to be stored. My tentative table is this:

SessionAnswers
   sqID
   ansID
   saOrder

The thing is that sqID points to queID, but so does ansID. That means that I could use sessID on this table or sqID. I’m not sure which one to pick. This setup still makes it possible for ansID to be mapped to an answer that is mapped to a question that is not even on SessionQuestions, which would be incorrect. Can I improve the setup to avoid that?

  • 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-05-29T05:34:40+00:00Added an answer on May 29, 2026 at 5:34 am

    Diamond-shaped dependencies benefit from natural keys (as opposed to surrogates). Natural keys can “merge” at the bottom of the “diamond”, producing the correct referential integrity behavior.

    In your case, using the natural key in SessionQuestions ({sessID, queID} as opposed to surrogate {sqID}), enables propagation of all the parent key “components” down both “edges” of the diamond, making it impossible to have a session answer whose question is not in the same session.

    Your model should look like this:

    enter image description here

    NOTE: Since per-session answer can be identified by order too, you need one additional alternate key in SessionAnswers (denoted by ‘U1’ above). Note that neither queID nor ansID should be included in that key – doing otherwise would allow two different answers to occupy the same “slot”.

    — EDIT —

    @tandu, I see you accepted my answer so I should probably stop while I’m ahead 😉 but I’d still like to propose an alternative design:

    enter image description here

    This should enable you to keep both history and order. When user enters a set of answers, they are recorded in SessionAnswers with version=1. If one or more of the answers are changed, a version=2 is created and so on…

    Each session version has 2 sets associated with it:

    • A set of unique questions, each with one answer (enforced through PK).
    • A set of “slots” used for ordering (enforced through alternate key).

    And since both are contained in the same table, this implies that each question maps to exactly one slot and each slot to exactly one question.

    BTW, this also enables you to change the order between versions if needed.

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

Sidebar

Related Questions

May be a stoopid question: I have a number of reference tables in an
This may be a stupid question but I just can't find the answer. What
I have a hunch this may be related to closures (or, a lack thereof).
This may seem trivial but I have no idea how and the lack of
May be I am getting old, but I can't find it...
I'm trying to create a table class, who's rows and columns may expand or
hello creating a custom object may be a widely published topic, but my lack
This may be very simple question, sorry about my lack of knwoledge, and my
I'm slightly puzzled by the lack of documentation on the issue, so I may
I'm hitting a bit of a brick wall I may just lack some fundamental

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.