To start off, I’m not that great with database strategies, so I don’t know really how to even approach this.
What I want to do is store some info in a database. Essentially the data is going to look like this
SensorNumber (int)
Reading (int)
Timestamp (Datetime?)(I just want to track down to the minute, nothing further is needed)
The only thing about this is that over a few months of tracking I’m going to have millions of rows (~5 million rows).
I really only care about searching by Timestamp and/or SensorNumber. The data in here is pretty much going to be never edited (insert once, read many times).
How should I go about building this? Is there anything special I should do other than create the table? and create the one index for SensorNumber and Temp?
Based on your comment, I would put a clustered index on
(Sensor, Timestamp).This will always cover when you want to search for SENSOR alone, but will also cover both fields checked in combination.
If you want to ever search for
Timestampalone, you can add a nonclustered index there as well.One issue you will have with this design is the need to rebuild the table since you are going to be inserting rows non-sequentially – the new rows won’t always belong at the end of the index.
Also, please do not name a field
timestamp– this is a keyword in SQL Server and can cause you all kinds of issues if you don’t delimit it everywhere.