SQL Server と ASP.NET を使用する場合、Date
vsを使用する際のパフォーマンス/ストレージに関する考慮事項はありDateTime
ますか?
要らなくてもDateTime
ほとんどのことに使ってる
SQL Server と ASP.NET を使用する場合、Date
vsを使用する際のパフォーマンス/ストレージに関する考慮事項はありDateTime
ますか?
要らなくてもDateTime
ほとんどのことに使ってる
DateTime takes 8 bytes per value
Date is 3 bytes.
I can't speak for low level performance; however in general we've found it a mistake to store values as DateTime by default. Sooner or later you run into the UTC issue and have to start working out offsets for dates that have 00:00:00.000 in the time portion!
If you're just storing dates I'd stick to the Date datatype; you'll fit more rows per page and save yourself a lot of hassle
Depends how many rows you're storing, and what you're using it for. Date is 3 bytes, DateTime is 8 bytes. Can quickly add up when you have billions of rows of data, or are using it for an index. Naturally there is a difference in the resolution of the value stored too. There are other date-types between date and datetime too such as smalldatetime that are more compact, again with different compromises.
考慮事項:
DATE
型は SQL Server 2008 で導入されたため、アプリは SQL Server 2005 と互換性がなくなりましたDate
- .NET クラスDATE
に変換されますDateTime
DATE
SQL 型に適していますDATETIME
あなたは何時間も何分も切り取ることができますCAST(@myDateTimeParam AS DATE)
私の経験から: 私はこの新しい型が好きで、T-SQL や C# のプログラミング中に問題はありませんでした
これに注意してください(比較時の日付のデータ型の混合):
DECLARE @startDay DATE = '2012-04-11' -- day
DECLARE @endDay DATE = '2012-04-13' -- day
DECLARE @eventTime DATETIME = '2012-04-13 12:00' -- point in time (noon)
IF @eventTime BETWEEN @startDay AND @endDay PRINT 'In period.' ELSE PRINT 'Not in period!'
結果は次のとおりです。
Not in period!
BETWEEN
比較すると、 (特定の時点まで; と共通の型)@endDay
にキャストされました。DATETIME
@eventTime
と比べて:
DECLARE @startDay DATE = '2012-04-11' -- day
DECLARE @endDay DATE = '2012-04-13' -- day
DECLARE @eventTime DATE = '2012-04-13' -- day
IF @eventTime BETWEEN @startDay AND @endDay PRINT 'In period.' ELSE PRINT 'Not in period!'
結果:
In period.
そしてそれで:
DECLARE @startDay DATETIME = '2012-04-11' -- day, but point in time in fact 00:00.000
DECLARE @endDay DATETIME = '2012-04-13' -- day, but point in time in fact 00:00.000
DECLARE @eventTime DATETIME = '2012-04-13' -- day, but point in time in fact 00:00.000
IF @eventTime BETWEEN @startDay AND @endDay PRINT 'In period.' ELSE PRINT 'Not in period!'
結果:
In period.