I would answer with: Keep it as it is with datetime!
One of the reasons is simple really, data type precedence. So, if you were ever to compare a datetime
to an integer
, the engine will decide that rather than converting date
->int
then compare int = int
, it will convert int
->datetime
and compare datetime = datetime
. Which stands the same for every single data type (like varchar
) except for:
- user-defined data types
- sql_variant
- xml
in that order of precedence.
Date comparison functions are also optimized to a crazy degree and they run blitzing fast, so you won't be gaining much in terms of performance, in fact you might end up losing performance since you have to do a join
operation and then (again) do a where
(how else would you filter by dates after all, generated ID != date you're comparing with).
So you need to ask yourself, is it really necessary to move date into a separate table? If you're planning on having a Data Warehouse, it might help with making the TimeDim table but other than that I see no reason to do so.
If you are interested in data precedence, you can see the list here (highest to lowest, top to bottom): https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-type-precedence-transact-sql?view=sql-server-2017