DateTime2 vs DateTime in SQL Server

前端 未结 14 1333
谎友^
谎友^ 2020-11-22 06:04

Which one:

  • datetime
  • datetime2

is the recommended way to store date and time in SQL Server 2008+?

I\'m aware of differ

14条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 06:38

    The MSDN documentation for datetime recommends using datetime2. Here is their recommendation:

    Use the time, date, datetime2 and datetimeoffset data types for new work. These types align with the SQL Standard. They are more portable. time, datetime2 and datetimeoffset provide more seconds precision. datetimeoffset provides time zone support for globally deployed applications.

    datetime2 has larger date range, a larger default fractional precision, and optional user-specified precision. Also depending on the user-specified precision it may use less storage.

提交回复
热议问题