从维度数据仓库设计中取出一个页面,并将日期存储在他们自己的带有 DateID 的表中:
DateID DateValue
------ ----------
1 2000-01-01
... ...
9999 2012-12-31
然后将您的所有日期字段——预测、实际、支付等——转换为对日期表的 DateID 字段的外键引用。
要填充日期表,您可以采用两种方式:
使用一些 VBA 生成大量日期,例如 2005-01-01 到 2100-12-31,并将它们作为一次性操作插入到日期表中。
每当有人输入新日期时,请检查日期表以查看它是否已存在,如果不存在,请插入它。
无论采用哪种方式,显然都需要 DateValue 上的索引。
Taking a step back from the actual question, I'm realising that you're trying to fit two different uses into the same database--regular transactional use (as your project management app) and analytical use (tracking several different dates for your milestones--in other words, the milestone completion date is a Slowly Changing Dimension). You might want to consider splitting up these two uses into a regular transactional database and a data warehouse for analysis, and setting up an ETL process to move the data between them.
This way you can track only a milestone completion date and a payment date in your transactional database and the data warehouse will capture changes to the completion date over time. And allow you to do analysis and forecasting on that without bogging down the performance of the transactional (application) database.