Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Database structure - best fit for recording lists

Posted on 2013-12-11
7
Medium Priority
?
231 Views
Last Modified: 2013-12-11
Hi,

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
username

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

OR like this (option 2) -

master table:
unique ID
form name
date/time returned
username

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,

Paul
0
Comment
Question by:PaulBS
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 2000 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
username
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."
0
 
LVL 9

Expert Comment

by:QuinnDex
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

FormsTB

formid,
formname,
active,
datecommenced
dateended

UserTB

UserID
username
realname
password
email
contactdetails
dateregistered

QuestionTB

QuestionID
FormID
DateUploaded
Active
QuestionText

AnswerTB

AnswerID
QuestionID
FormID
UserID
AnswerText
DateAnswered
0
 
LVL 40

Expert Comment

by:lcohan
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 unless...you 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 indeed...is good to consider and learn from advice/suggestions you will get.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:QuinnDex
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
0
 
LVL 70

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 )
0
 

Author Comment

by:PaulBS
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.

Paul
0
 

Author Closing Comment

by:PaulBS
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.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

972 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