Question

Okay now let me give an example

date : 15.12.2012 00:16:39

Now this will be stored as

20121215001639

Now for example if i want to retrieve rows older than 30 min (30*60=1800 sec)

I can do just as

where date<20121215001639+1800 

So would this be a performance way instead of storing as date time ?

Was it helpful?

Solution

I fully agree with marc_s's comment above, but I decided to make a test, just for fun.

I created two tables, one with a datetime column and one with a bigint column, representing the same data.

Here is the sql fiddle: http://www.sqlfiddle.com/#!3/74976/3

I've run this query for 500, 1000 and 5000 records and every time noticed that the execution plans are identical, so from a performance point of view there's no gain in using bigint.

However, there are obvious downsides for the bigint approach; some of them:

  • the conversion to/from bigint requires more code to be written
  • operations like filtering by month require more complex/less readable queries
  • looking at the result grid in Management Studio, you cannot "parse"/interpret the results as quickly as you could if you saw the separated date parts.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top