我需要创建一个表,保存包含设备id(int),logdate(datetime)和值(十进制)(SQL Server 2008)的测量值。测量总是在本季度。 00:00,00:15,00:30,00:45,01:00,01:15 ...所以我在想,定义自某个日期以来宿舍数量的整数将导致更好的性能约会时间。测量的最佳性能表设计
检索通常会使用来完成以下事项:
-where DeviceId = x and QuarterNumber between a and b
-where DeviceId in (x, y, ...) and QuarterNumber between a and b
-where DeviceId = x and QuarterNumber = a
什么是此表的最佳设计?
PK DeviceId int
PK QuarterNumber int
Value int
或
PK MeasurementId int
UQ QuarterNumber int
UQ DeviceId int
Value int
(UQ =唯一索引)
或完全不同的东西?
谢谢!
您期望录制多少个季度?您希望注册多少设备? – Andrew 2012-08-03 08:15:25
大约100.000个设备,我会为每个设备保留大约96 * 5个宿舍。 – Bruno 2012-08-03 08:17:28
我总是倾向于选择2.在这种情况下,我不知道哪个更好。选项2意味着你会意味着更大的表和索引,但我认为插入会更快。我认为对于选项1,由于PK上的聚集索引,您可能会遇到问题。 – Andrew 2012-08-03 08:25:56