I need to build a database for storing assessments.
Each assessment can have an indefinite number of questions, and an indefinite number of responses.
Responses for each assessment can grow up to 500k.
Questions for each assessment can be from 10 to 200.
While the Assessments and AssessmentResponses tables will be designed with the "normal" relational table, Questions and Answers should be stored as Key/Value pair.
Assessments
|AssessmentID|Name|JsonSchema|
Questions
|QuestionID|AssessmentID|QuestionValue|QuestionType|
AssessmentResponses
|ResponseID|AssessmentID|RespondentName|Date|JsonResponse|
Answers
|ResponseID|QuestionID|AnswerValueText|AnswerValueDecimal|
As you can see I store also the assessment schema and the responses in JSON format as I found it useful to quickly visualize on a web UI. JsonResponse, in particular, contains all the answers given in the related response, like the following:
{
"interviewDate":"2001/12/28",
"city":"Mombasa",
"phone":"123456789",
"name":"Marco",
"age":16
}
Typical queries can be:
- Extract all the answers (paged) of a particular AssesmentID.
- Calculate the average on all the answers of a particular AssessmentID of the age key.
- Extract all the responses where the key "age" has a value greater than 25 and the key "city" is equal to "New York"
Please note that for query No.2, the age values will be stored in the column AnswerValueDecimal, where I will store all the numeric values.
I'm wondering if the column store index will increase the performance in this structure?
Please note that I know that an ElasticSearch instance will help me a lot but for a budget issue we can't implement at this stage.
Some more details about data
Answers to the questions in the assessments are generally chosen from a limited number of choices. In example:
- Are you married? > [YES,NO]
- Type of building? > [Concrete,Skeleton,Eternite Sheets,Iron Sheets,Other]
- City Area? > [North,South,East,West,center]
The queries can be built by the end-user depending on the information they need from a particular assessment. Giving the above example, they want to know how many Eternite buildings are in the North and West area of the city, a count in the end.
But for example there is also a question "How old are you?", they want to filter the previous query to know how many Eternite buildings are in the North and West area where there's a person with an age lower than 25 years...
USING JSON FIELD TO STORE DATA
I've tried using the new feature in SQL Server 2016/2017 to store JSON document inside an NVARCHAR(MAX) field. It seems to work pretty well but maybe only once the whole table is loaded in memory.
Here is the dbfiddle: https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=2ce135dc37d72f9db951bbb4e2708baa