how to save answers

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

how to save answers

Post by yacahuma »

If you had to save the answer of an exam, and the exam had 1000 questions. Will you save the answers like
OPTION #1:
COLUMNS: EXAM_ID | USER_ID | Q1 | Q2 | Q3| ... | Q1000
Ej of a row
1 | 1 | a|b|c|d......|x

OR
OPTION #2:
COLUMNS: EXAM_ID | USER_ID | Q_ID | ANSWER
EJ
1 | 1 | 1 | a
1 | 1 | 2 | b
1 | 1 | 2 | c

Why?
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: how to save answers

Post by Hannes2k »

Hi,
I would prefer the second solution, because, creating 1000 columns isn't a nice job and displaying it with a database managment tool won't be possible.

And:
With option#2 you can easily extend your system. Maybe the new test have 1010 questions or just 990? And what happen if you create a second test with just 50 questions?
With option #2 you can store the answers for each test in your database. You could theoretical also store the answers for a multiple choice question. This won't be possible with Option #1.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: how to save answers

Post by yacahuma »

thank you.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: how to save answers

Post by aceconcepts »

To normalise it further you could create an additional table to house user id with exam id thus there would be no need to have exam id in option#2.
Post Reply