title: Why is datekey in fact tables always INT?
body: <p>I'm looking at the <code>datekey</code> column from the fact tables in <code>AdventureWorksDW</code> and they're all of type <code>int</code>.</p>
  
  <p>Is there a reason for this and not of type <code>date</code>?</p>
  
  <p>I understand that creating a clustered index composed of an <code>INT</code> would optimize query speed. But let's say I want to get data from this past week. I can subtract 6 from date <code>20170704</code> and I'll get <code>20170698</code> which is not a valid date. So I have to cast everything to <code>date</code>, subtract, and then cast as <code>int</code>.</p>
  
  <p>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 <code>Date</code> 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.</p>
  
  <p>It seems like a lot of hassle and not many benefits.</p>
  
  <p>Thanks.</p>