I support an existing application written by another developer, and I have a question whether the choice of the type of data that the developer chose to store dates affects the performance of certain queries.
Relevant information: the application heavily uses the "Date of business" field in one of our tables. The data type for this business date is nvarchar (10), not the datetime data type. The date format is "MM / DD / YYYY", so Christmas 2007 is stored as "12/25/2007".
In short, we have several heavy queries that run once a week and take a lot of time.
I am rewriting this application from scratch, but as I look at it, I want to know if there is a difference in performance between using the datetime data type compared to storing dates since they are in the current database.
You will save disk space and increase performance if you use datetime instead of nvarchar (10).
If you use date fields to perform date calculations (DATEADD, etc.), you will see a significant increase in query execution speed, since the fields should not be converted to datetime at runtime.
DATETIME , VARCHAR, DATETIME s.
DATETIME
VARCHAR
, SELECT (, , DATEDIFF , WHERE ..), .
SELECT
DATEDIFF
WHERE
, DateTime, varchar . ... :
SELECT * FROM Table WHERE DateField > '12/25/2007'
.
, datetime , , varchar. , UNIX .
. datetime , varchar nvarchar ( nvarchar - ?)? .
, .
, (>/</= , ), "id" , int yyyymmdd, . , , "" , , "", , datetime NULL 1/1/1900 - . foerign "" .
>/</=
NULL
, "sql-", , SQL Server, datetime, smalldatetime. , SQL Server 2008 date, datetime2 . ,
datetime
smalldatetime
date
datetime2
, Datetime , 4- , nvarchar (10) 22 ( + 2 .). Datetime.
, , , , . , , , , , , , .
, Datetime - .
, datetime , , , DATETIMES - . , , Date, , .
, , , - .
nvarchar , , , . "//". , "12/25/2007" "12/01/2008" nvarchar, , . "yyyy/mm/dd" .
, . , , . , .
varchar ( ) , , , , . datetime, , , ASAP, Unknown, 1/32/2009 .. , , .
, , varchar , . .
Source: https://habr.com/ru/post/1702485/More articles:Why (string) int32 always throws: it is impossible to convert the type 'int' to 'string' - c #ToString () does not return the expected string - genericsError accessing RSS feed from Silverlight using WebClient () - silverlightBest way to implement MySQL hash table? - mysqlDefining Grails Domain ID in Bootstrap.groovy - grailsHow to write binary data for 7z archive format? - c ++Widget wag = * new widget () - c ++How can I make friendly URLs for my site? - apacheHow to install MonoDevelop on my Mac? - monodevelopError opening serial port - .netAll Articles