"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, April 30, 2011

Difference between datetime and smalldatetime datatype in SQL Server 2005

Choosing between datetime and smalldatetime datatype in SQL Server 2005

datetime datatype are used for storing date and time information.

Comparision chart

Data type
Range
Storage/Accuracy
datetime
January 1, 1753, through December 31, 9999
4 Bytes/3.33 milliseconds
smalldatetime
January 1, 1900, through June 6, 2079
2 Bytes/1 minute


datetime is more accurate than smalldatetime datatype.
datetime datatype stores milliseconds data while smalldatetime
datatype doesn't store millisecond data and thus it is less accurate.
But in most cases we don't require such a accurate information, so
in this case you can storing datetime in smalldatetime datatype and saves the extra 2 bytes storage space.
Example: DOJ details of employee doesn't require such a accuracy level so you can use smalldatetime datatype.


Have a nice day... 'N happy Coding :)

No comments: