A niave beginners question about database design.
I have an app managing some logger data eg. 1000s of sequential measurements of time, voltage, current, temperature. In addition each sequence run has meta data (date, location, etc).
So I need a table for each set of measurements and a master table listing these tables and the meta data for each.
A couple of questions:
This doesn’t really use the fact that all the data tables are the same format – there is no ‘array of tables’ concept, does this mean anything?
Would I just give each data table a unique name, put that in the main table as a column, then simply substitute it into the SQL select statement – or is there a better way?
edit: The reason for many tables, one per run, is that there might be 10-100 runs each with many 1000s of measurements. If I want to display/query/delete just one run it seemed more natural to have each in it’s own table.
It looks like this is a programmer mindset (everything should be collections of separate objects) the database approach seems to prefer – store everything together and use index/cross-references.
BTW, I want to address the question of whether it’s a pain to manage all the data in one table, versus having multiple tables.
Starting assumption: you’re going to want to at least have a meta-data table to store the experiment meta-data, and one-or-more table(s) to store the measurements.
If you take the ‘I want a table for each measurement set’ approach, you’ll need to know the name of the table. So your metadata table will look something like:
And a table for each experiment, each looking the same:
Then in your program, you first need to fetch the metadata:
which will, amongst other things, return measurementTableName for the experiment of interest (say Measurement0002). Then, your next query is:
Now, let’s take the ‘store all the data in the measurement table’ approach. Your metadata table will look like:
And a table for all experiments.
Then, just as before, you first need to fetch the metadata:
which will, amongst other things, give you the measurementSetID which you will use to get only the the measurements from the desired set (let’s say id=2). Then, your next query is:
So let’s compare the two approaches… The metadata queries are essentially identical. The only difference is that in the first case, you are retrieving the measurementTableName for the desired experiment table; while in the second case, you are retrieving the measurementSetId for the desired entries in the measurements table.
The measurement-fetching queries are essentially the same, too:
The only variable is either the table name, or the measurementSetID:
The query result is almost the same, the second approach will just give you an extra column in your data (the measurementSetID) which you can ignore, because all returned rows will have the same set ID.