Menu

1 / 3

SQL Server DATETIME vs DATETIME2: Which to Use, and What Converting an Existing Column Costs

DEV Community: dotnet·Son Tran·7 days ago
#pZvZjha8
#devtodotnet#devto#dev#datetime2#datetime
Long article (1935 words) — no AI summary yet.
Reading 0:00
15s threshold

Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples.

TL;DR: Use DATETIME2(3) for new columns: it keeps exact milliseconds in 7 bytes, while DATETIME rounds to steps of 1/300 second in 8. Converting an existing column means dropping its default and indexes first, then a rewrite of every row under a schema lock, about 1.4 seconds and 106 MB of log on one million rows in our test. Pick a precision of 3 or more, or the conversion rounds stored values without an error.

For a new SQL Server column, use DATETIME2(3) : it keeps exact milliseconds in 7 bytes, where DATETIME rounds every value to a step of 1/300 second and takes 8. The harder question is the column you already have.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.