I have a Database with SQL Server: it stores measurements from some sensors, the table looks like that:
|MEASUREID|SensorID*|Temperature|Humidity|dateandTime|
MEASUREID
is the PK (it´s an integer
created automatically from SQL Server. +1 for each new record) and SensorID
the FK. The table cointans a huge amount of data and is to be updated relatively often: update means new measurement have to be INSERTED into the table.
It could happen that the measures we want to save, already exist in the DB, and we don't want any duplicate to be stored.
Possible solutions I figured out:
- checking every time if a measure already exists will kill the performances
- I read about indexes. They should be pretty efficient for big tables but at the same time it´s not advisable to use them when Insert/update operations happen very often.
- I thought to use a combination of HASH functions and indexes:the MeasureID can be the result of a so called hash function
MID = f(sensID,temp,humid,dateandtime)
. MID is unique and could be indexed: if a new measure (temperature, humidity etc.) has to be inserted, you can retrieve the hash function to produce the corresponding MID and easily check if that MID already exists.
What do you think about it? Do you have any other idea?? Thanks :)