Blee
Blee

Reputation: 87

Database Design for logging multiple answers

I am designing a database for a project I am working on. I have 3 tasks (which the user can choose from)

First task gives 10 questions Second task gives 20 questions Third task gives 30 questions

I have come up with an improved design but I am still struggling.

It looks like :

User (user_id, Name, reg_date)

Test (test_id, task_type [either 1,2,3], category [there are 5 different categories] )

Response (Response_id, user_id, test_id, response_date, response_1a, response_1b, response_2a, response_2b, ... , response_30a, response_30b)

For each question, there are going to be two answers. Answer 1 and Answer 2. So if there are 10 questions, there are going to be total of 20 answers logged. Each answer will be a decimal value from 0~1.0.

But, I run in to the problem of having +120 columns for the Response table.

Notice that if the test_id is 1, there would be only 10 questions, so the columns in Response table from response_11a to response_30b would be null.

An example record would be:

Response (1, 1, 1, 2015/04/30, 0.5, 0.5, 0.7, 0.7, 0.8, 0.8, ... (a lot of records)... , 1.0, 0.3, null, null, null, (all nulls because there are only 10 questions for test_id 1. ) )

I cannot think of another way of doing this. :/

Is this a good way of designing the database?

EDIT:

I had an idea of doing this.

User (user_id, Name, reg_date)

Test (test_id, task_type [either 1,2,3], category [there are 5 different categories] )

Response (resp_id, user_id, test_id, resp_date)

answers (resp_id (links to response table), current_question_number, ans1, ans2)

So if there are 10 questions, in the answers table, there would be 10 records that look like:

(1, 1, 0.0, 0.0)
(1, 2, 0.0, 0.5)
(1, 3, 0.3, 0.6)
(1, 4, 0.5, 0.5)
...
(1, 10, 0.3, 0.3)

How is this design?

Later on, I will be using this data to plot out a graph so I need each responses to be easily accessible.

Upvotes: 0

Views: 499

Answers (3)

Mahesh Kava
Mahesh Kava

Reputation: 791

You need to further normalise your table. You would need another table 'questions' to prevent redundant data storage.

enter image description here

Upvotes: 0

Jerry
Jerry

Reputation: 19

I have one suggestion for the database design.

i have made a few modification in Response Table and Create a new Table.

  • USER Table (User_ID [PK],USER_NAME,another Extra fields)
  • TEST Table (Test_ID [PK],some other fields for test details)
  • Quest_Set Table (Set_ID ,Que_ID,Question,some other fields if required)
  • RESPONSE Table (Res_id ,User_ID [FK],Test_ID [FK], Set_ID , Que_ID, Ans_1 , Ans_2 , Flag)

Please review it and let me know if you have any confusions.

Regards.

Please look the New_Response Table

(Response_id, user_id, test_id,Trans_id,Ans1,Ans2,Flag)

Upvotes: 0

woodwa
woodwa

Reputation: 101

In database design you regularly have to consider more fields or more records and how normalised the database needs to be what you have suggested above isn't entirely normalised.

DB101 Normalisation http://en.wikipedia.org/wiki/Database_normalization

I'd suggest a 4th table and maybe 5th Table

  • User: PK UserID, Attributes such as address..
  • Test: PK TestID, Some extra attributes
  • Question (2xPrimary fields one is foreign key) TestID , QuestionID,
  • Response (3xPrimary fields two are foreign key) TestID , QuestionID, ResponseID, Some extra attributes

Upvotes: 1

Related Questions