Proper Datatype Usage Guaranteed Better Performance and Accuracy
Proper Datatype Usage Guaranteed Better Performance and Accuracy
RabeData, LLC
Why do we care?
Performance, accuracy
Data Type by Data type
When to use which
Functions and Nuggets
What to use, what not to use, some workarounds
Why Important?
Accuracy •
Performance •
SARGable (Implicit Conversion) •
Implicit Conversion
Data Type Precedence
Numeric
Character
Temporal
Binary
Other
Numeric Category
Date literals •
‘1/2/11’?
‘01-02-2011’?
‘2011-01-02’?
Using BETWEEN to identify day •
Adding days •
What date is 0 or “” (empty string)? •
Eliminating time •
Binary Category
cursor
timestamp/rowversion : 8 bytes
hierarchyid
uniqueidentifier : 16 bytes
sql_variant
xml
Spacial Geometry Types
Spacial Geography Types
table
Other Category
cursor
timestamp/rowversion : 8 bytes
hierarchyid
uniqueidentifier : 16 bytes
sql_variant
xml
table
Functions
ISNUMERIC •
TRY_CONVERT / TRY_CAST •
Watch out for empty strings to temporal
ISDATE •
Doesn’t cover entire date range
Doesn’t support full resolution of datetime2
ISNULL vs. COALESCE •
ISNULL returns data type of first argument
COALESCE returns data type of highest precedence
Temporal Functions •
CURRENT_TIMESTAMP
GETDATE()
GETUTCDATE()
SYSDATETIME()
SYSUTCDATETIME()
Summary
Pick data types with consideration
Size matters
Domain constraint
Avoid deprecated data types
Beware of implicit conversions
Not SARGable
Unexpected results
Use functions with caution
Please provide feedback on the
presentation
https://www.surveymonkey.com/r/PSKT9VC
Thanks. Questions?
Vern
Rabe
[email protected] @VernRabe