How to use? A string or 15 integer fields

database-designdatatypesperformancequery-performance

I am developing a student tracking program where I need to store 15 exam marks.

I can store the marks as a string and split them up when I need to, for purposes such as performing arithmetical operations. However, I need as much performance as possible.

Which is better? A single string field, or 15 individual int fields?

Best Answer

If you are already talking about splitting and computing, don't store this as an array.

Regardless of the relational theory and traditional normalization rules and dogma, it's simply a design which gives you MINIMAL flexibility.

Make each exam result a row.

I'm not trying to anticipate everything, but there are a very large number of things which this more granular (and, yes, normalized) and only ever so slightly more space expensive design facilitates which you may or may not need now and may or may not need in the future:

  • Throwing out highest and lowest result? You will have to slice up your array and sort it.

  • Averaging? You will have to slice it up and total it

  • Analysis of exam result by exam across students? You'll have to slice and pivot

  • Sorting for counting (or instance British GCSEs, where it might be 7 As and 2Bs)? You'll have to slice and sort

Note that all this slicing and sorting comes very cheaply in an indexed, normalized design.