I'm looking at the datekey
column from the fact tables in AdventureWorksDW
and they're all of type int
.
Is there a reason for this and not of type date
?
I understand that creating a clustered index composed of an INT
would optimize query speed. But let's say I want to get data from this past week. I can subtract 6 from date 20170704
and I'll get 20170698
which is not a valid date. So I have to cast everything to date
, subtract, and then cast as int
.
Right now I have a foreign key constraint to make sure that something besides 'YYYYMMDD' isn't inserted. It wouldn't be necessary with a Date
type. Just now, I wanted to get some data between 6/28 and 7/4. I can't just subtract six from `20170703'; I have to cast from int to date.
It seems like a lot of hassle and not many benefits.
Thanks.
int
(4 bytes) would be more efficient than one ondate
datatype (3 bytes)? – DropoutINT
key that creatively encodes a date, which I can't see having any benefit over an actual date/time type. – Tannertannery