0% found this document useful (0 votes)
11 views3 pages

SQL Server Data Types Overview

The document discusses data types in SQL Server, noting that each column, variable, expression and parameter has a related data type that specifies what type of data it can hold (numbers, text, dates, etc.). It provides examples of system-supplied and user-defined data types in SQL Server and how data type characteristics are determined when different types are combined. Finally, it categorizes and lists the various data types available in SQL Server.

Uploaded by

Heeone
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

SQL Server Data Types Overview

The document discusses data types in SQL Server, noting that each column, variable, expression and parameter has a related data type that specifies what type of data it can hold (numbers, text, dates, etc.). It provides examples of system-supplied and user-defined data types in SQL Server and how data type characteristics are determined when different types are combined. Finally, it categorizes and lists the various data types available in SQL Server.

Uploaded by

Heeone
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Data types (Transact-SQL)

THIS TOPIC APPLIES TO:  SQL Server (starting with 2008) Azure SQL Database Azure SQL
Data Warehouse  Parallel Data Warehouse

In SQL Server, each column, local variable, expression, and parameter has a related data type. A data
type is an attribute that specifies the type of data that the object can hold: integer data, character data,
monetary data, date and time data, binary strings, and so on.

SQL Server supplies a set of system data types that define all the types of data that can be used with SQL
Server. You can also define your own data types in Transact-SQL or the Microsoft .NET Framework. Alias
data types are based on the system-supplied data types. For more information about alias data types,
see CREATE TYPE (Transact-SQL). User-defined types obtain their characteristics from the methods and
operators of a class that you create by using one of the programming languages support by the .NET
Framework.

When two expressions that have different data types, collations, precision, scale, or length are
combined by an operator, the characteristics of result are determined by the following:

 The data type of the result is determined by applying the rules of data type precedence to the
data types of the input expressions. For more information, see Data Type Precedence (Transact-
SQL).

 The collation of the result is determined by the rules of collation precedence when the result
data type is char, varchar, text, nchar, nvarchar, or ntext. For more information, see Collation
Precedence (Transact-SQL).

 The precision, scale, and length of the result depend on the precision, scale, and length of the
input expressions. For more information, see Precision, Scale, and Length (Transact-SQL).

SQL Server provides data type synonyms for ISO compatibility. For more information, see Data Type
Synonyms (Transact-SQL).

Data type categories

Data types in SQL Server are organized into the following categories:

Exact numerics Unicode character strings

Approximate numerics Binary strings

Date and time Other data types

Character strings
In SQL Server, based on their storage characteristics, some data types are designated as belonging to the
following groups:

 Large value data types: varchar(max), and nvarchar(max)

 Large object data types: text, ntext, image, varbinary(max), and xml

Note

sp_help returns -1 as the length for the large-value and xml data types.

Exact numerics

bigint numeric

bit smallint

decimal smallmoney

int tinyint

money

Approximate numerics

float real

Date and time

date datetimeoffset

datetime2 smalldatetime

datetime time

Character strings

char varchar
text

Unicode character strings

nchar nvarchar

ntext

Binary strings

binary varbinary

image

Other data types

cursor rowversion

hierarchyid uniqueidentifier

sql_variant xml

Spatial Geometry Types Spatial Geography Types

table

Common questions

Powered by AI

The precision, scale, and length of the result in SQL Server depend on the precision, scale, and length of the input expressions when two numeric expressions are combined . This affects how the final result is calculated and stored, potentially impacting accuracy and storage requirements.

Alias data types in SQL Server are based on the system-supplied data types and are created with the CREATE TYPE command . User-defined types obtain their characteristics from the methods and operators of a class that you create using a .NET Framework supported programming language .

A developer might choose an exact numeric data type, like decimal or int, over an approximate numeric type, such as float or real, to guarantee precision in calculations. Exact numeric types store data exactly as input, which is crucial for financial and transactional operations where accuracy is important .

The collation of the result in SQL Server is determined by the rules of collation precedence when the result data type is char, varchar, text, nchar, nvarchar, or ntext . Collation affects comparison and sorting of the character data.

The uniqueidentifier data type in SQL Server is used to store globally unique identifiers (GUIDs) usually created via NEWID or NEWSEQUENTIALID functions. Its primary advantage is that it ensures the uniqueness of values across tables and databases, which is particularly useful for distributed systems where identity integrity is crucial .

Data type synonyms in SQL Server ensure compatibility with ISO standards by allowing developers to use familiar SQL data type names that might be standard across various database systems. This aids in ease of migration and understanding across different systems and platforms .

SQL Server determines the result data type by applying the rules of data type precedence to the data types of the input expressions . This means that the data type with the higher precedence is used for the result.

Spatial geometry types in SQL Server allow for the representation of planar, projective space data (Euclidean) and are typically used for CAD and geographic systems not involving latitude-longitude data. Spatial geography types specifically handle ellipsoidal (round-earth) data using latitude-longitude pairs, suitable for earth's mapping applications . The choice between the two depends on the specific requirements of the spatial analysis being conducted.

Choosing the correct data type in SQL Server is critical for performance optimization and data integrity because it directly affects data storage, indexing efficiency, and the speed of query processing. Proper data types ensure that data is stored efficiently without unnecessary space usage, and indexes operate effectively . Misaligned types can lead to data truncation, rounding errors, or even corruptions, impacting data integrity.

Large object data types, like text, ntext, image, and xml, are intended for storing large amounts of data, often binary in nature. Large value data types, such as varchar(max) and nvarchar(max), are used for character string data that exceeds typical size limits . Understanding the distinction is important for optimizing storage and performance.

You might also like