Database Performance and Data Types

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.

+3
source share
9 answers

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.

+6
source

DATETIME , VARCHAR, DATETIME s.

, SELECT (, , DATEDIFF , WHERE ..), .

+3

, DateTime, varchar . ... :

SELECT *
FROM Table
WHERE DateField > '12/25/2007'

.

0

, datetime , , varchar. , UNIX .

0

. datetime , varchar nvarchar ( nvarchar - ?)? .

, .

, (>/</= , ), "id" , int yyyymmdd, . , , "" , , "", , datetime NULL 1/1/1900 - . foerign "" .

, "sql-", , SQL Server, datetime, smalldatetime. , SQL Server 2008 date, datetime2 . ,

0

, Datetime , 4- , nvarchar (10) 22 ( + 2 .). Datetime.

, , , , . , , , , , , , .

, Datetime - .

0

, datetime , , , DATETIMES - . , , Date, , .

, , , - .

0

nvarchar , , , . "//". , "12/25/2007" "12/01/2008" nvarchar, , . "yyyy/mm/dd" .

, . , , . , .

0

varchar ( ) , , , , . datetime, , , ASAP, Unknown, 1/32/2009 .. , , .

, , varchar , . .

0

Source: https://habr.com/ru/post/1702485/


All Articles