Database structure - best fit for recording lists

Posted on 2013-12-11
Last Modified: 2013-12-11

Odd question but my brain is melting over this one:

I have a form (on an iPhone) that returns answers to a number (about 10) of questions that will mostly return yes or no answers (although not exclusively so will be saved as a string) in an xml format. I expect about 20 users to complete the form every day and the forms may change over time and more forms may be added.

I want to store the data returned and have parsed the xml to extract the relevant information.

Should I create a tables to store that information like this (option 1) -

master table:
Unique ID
forms name
date/time returned

child table:
Unique ID
master table ID
question (in the form of a short code)

OR like this (option 2) -

master table:
unique ID
form name
date/time returned

child table:
unique ID
Master table ID
question 1 (in a short name form)
answer 1
question 2 (in a short name form)
answer 2
and repeat for each question/answer

I think option 1 as querying to find which fields have answered yes would be quick but the number of rows will grow to a large number very quickly

Option 2 will give less records but queries will be harder etc.

Thanks in advance,

Question by:PaulBS
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
LVL 40

Accepted Solution

lcohan earned 500 total points
ID: 39712552
Same old normalization vs. de-normalization question however in this case I would just create one table like:

Unique ID
forms name
date/time returned
question (in the form of a short code)
answer - as XML data that you can later parse and read

this would be useful as well considering "the forms may change over time and more forms may be added."

Expert Comment

ID: 39712572
if you plan to add additional forms over time and additional questions to existing forms i would separate forms from questions  into their own tables and have answers in their own table to

i would give a table to user details this should give you much better scalability in the future and should simplify queries in the long run

something like this








LVL 40

Expert Comment

ID: 39712613
If indeed "20 users to complete the form every day" and do not plan to have 100+ forms scalability should not be a problem in my opinion plan to keep the table(s) in a SQL Server on some mobile device:)

Quick math
  select 20(users)*1(form)*100000(days) = 2 000 000 over a period of
  select 100000/365  = 273 years

right? so you don't have that much data to be accumulated per form over a long period of time but good to consider and learn from advice/suggestions you will get.
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.


Expert Comment

ID: 39712631
lol i know, but scalability is always good to consider, and if this is a new venture, if something takes off in the mobile or internet infrastructures then it can become astronomically huge over night

many times this could but doesnt happen because the code falls over when a sudden influx of users starts, so dies straight away
LVL 69

Expert Comment

by:Scott Pletcher
ID: 39712688
DON'T shortcut the design process and just stick everything in one "table" (not really a table if there was NO design done on it).

Proper normalization is primarily for ease of maintaining accuracy, not performance.  Even 100 rows should be properly normalized, although obviously you avoid extreme normalization unless you have huge numbers of rows.

Here's my initial rough cut; naturally it needs further fleshing out as well:

Users ( user_id, user_name, first_name, last_name, ..., date_registered,
    password [encrypted, if possible], ... )

User_Contacts ( user_id, sequence(1=most preferred contact,2=next preferred contact,etc.), mode (email/phone/...), ... )

-- solely for the Qs themselves, w/o regard to any form;
--if a Q is significantly altered, you assign it a new question_id and
--adjust any form(s) accordingly
Questions ( question_id, question_text, question_description, date_originated, date_last_modified, date_ended, ... )

--about only the form itself, w/o regard to any qs
Forms ( form_id, name, date_originated, date_first_use, date_ended )

--form structure, w/o regard to any user
Form_Structure ( form_id, sequence(1=first q/element on form,2=2nd q/element on form,etc.), question_id (text of q could actually just be text to explain something on form or even a picture to be included at that point on the form, etc..), ... )

User_Forms ( user_id, form_id, date_asked, date_responded, was_completed, ... )

User_Answers ( user_id, form_id, question_id, answer )

Author Comment

ID: 39712841
Hi Guys, thanks for the quick response.

I should add that the forms themselves (and users list, questions etc) are created and managed in a separate system.

The structure I am trying to create is just for the output of the forms returned in xml.

In this initial case it is a vehicle check form which users complete on an iPhone. The answers are mostly set to yes already so the user just confirms the answers by signing and saving the form.

When I receive the xml output most answers will be yes (by default) but I need to check for any "no" answers and notify a manager with the text that one question allows.

I will also need to run reports to show vehicle issues over time as it part of our Health and safety and vehicle management system.

I think all agree (with various levels of implementation) that there is no good reason to create a Q/A table with multiple columns (for each question and answer) and one record for the whole response. Better to have just a few columns (fields) and multiple records per form returned.

In this case you all have answered with what I was thinking and I understand the comments regarding normalisation but since this is internal use only, rarely queried once stored and code and querying will be easier the more basic the structure is, I am going with the first answer.

Thanks all for contributing.


Author Closing Comment

ID: 39712844
Whilst not 100% the "proper" way to do it but easiest and for the purposes of this project quicker to implement and test so well done.

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question