有效日期记录表的键和索引设计

时间:2019-03-26 20:46:41

标签: sql-server database-design

我对SQL数据库设计和体系结构还很陌生。我正在创建一个表来保存源系统中价值6个月的每日快照文件。可以使用以下脚本创建数据表的截断版本:

CREATE TABLE AccountHist 
(
    EffectiveDate datetime not null,
    AccountNumber bigint not null,
    Balance float not null,
    Status char(3) not null,
    IntRate real not null,
  etc......
)

EffectiveDate和AccountNumber一起是唯一的,并且永远不应重复,因此我想向表中添加PK约束,但是我对于应该将其聚集还是应为NONCLUSETERD感到困惑:

CONSTRAINT PK_AcctEffDate PRIMARY KEY (?) (EffectiveDate, AccountNumber)

我对集群索引和非集群索引之间的区别有一个按书定义的理解。我觉得应该使用群集,因为,这是我认为最常见的方法,但是按有效日期对数据进行排序也很有意义。

让我感到困扰的是,我还需要为EffectiveDate和AccountNumber都使用非聚集索引。这是我希望运行的2个常见查询:

select AccountNumber, Balance from AccountHist
where EffectiveDate = (select max(EffectiveDate) from AccountHist)
and Status = 'ACT'

select EffectiveDate, Avg(IntRate) AvgRate from AccountHist
where EffectiveDate >= '01/01/2019' and EffectiveDate < '02/01/2019'
group by EffectiveDate

这归结为三个主要问题: 1.我可以在构成我的PK的2列上创建单独的索引吗?如果是这样,应该将哪些群集还是非群集? 2.我应该使用替代密钥吗? 3.哪种设置将在查询和加载数据方面产生最佳性能?

谢谢。

0 个答案:

没有答案
相关问题