I have a data structure something like this:
typedef struct tagSUB_DATA
{
double measuredValue;
double standardDeviation;
double calculatedValue;
double weightedError;
} SUB_DATA;
typedef struct tagALL_THE_DATA
{
int aNumber;
double aDouble;
SUB_DATA measurements1;
SUB_DATA measurements2;
} ALL_THE_DATA;
which I need to store in a relational database.
My query relates to the two fields, measurements1
and measurements2
. Obviously, they are the same type, so my first thought was "let's create a SUB_DATA
table and create a Foreign Key link between them".
Table: ALL_THE_DATA
Field: ID (int, Primary Key)
Field: aNumber (int)
Field: aDouble (double)
Field: measurements1 (int, Foreign Key referencing SUB_DATA)
Field: measurements2 (int, Foreign Key referincing SUB_DATA)
Table: SUB_DATA
Field: ID (int, Primary Key)
Field: measuredValue (double)
Field: standardDeviation (double)
Field: calculatedValue (double)
Field: weightedError (double)
However, the actual context of the data is such that measurements1
and measurements2
are measurements of different things (let's say, apples and oranges rockets), which both happen to need a measured value, standard deviation, etc. Is it still appropriate, then, to store the data for measured apples and measured rockets in the same table, even though they use the same data, or would it be more prudent to design it so that rockets and apples have their own (identically-designed) tables?
Table: ALL_THE_DATA
Field: ID (int, Primary Key)
Field: aNumber (int)
Field: aDouble (double)
Field: appleMeasurements (int, Foreign Key referencing APPLE_MEASUREMENTS)
Field: rocketMeasurements (int, Foreign Key referencing ROCKET_MEASUREMENTS)
Table: APPLE_MEASUREMENTS
Field: ID (int, Primary Key)
Field: measuredValue (double)
Field: standardDeviation (double)
Field: calculatedValue (double)
Field: weightedError (double)
Table: ROCKET_MEASUREMENTS
Field: ID (int, Primary Key)
Field: measuredValue (double)
Field: standardDeviation (double)
Field: calculatedValue (double)
Field: weightedError (double)
Which of these two solutions is best, do you think? The first seems less redundant, but may have greater potential for there being inconsistent data. Or perhaps is there a better way to solve this problem than I've thought of?
Cheers!
(Please excuse my Apples/Rockets pseudodata - I can't really post actual code here)
Extra Information:
In this case, we can be certain that rockets and apples will not change their fields later, so I'm not too worried about the case of "what if the fields in either rocket or apple change later".