Skip to content

Latest commit

 

History

History
138 lines (103 loc) · 7.35 KB

data-types-transact-sql.md

File metadata and controls

138 lines (103 loc) · 7.35 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic ms.custom helpviewer_keywords dev_langs monikerRange
Data types (Transact-SQL)
This article provides a summary of the different data types available in the SQL Server Database Engine.
MikeRayMSFT
mikeray
randolphwest
05/21/2024
sql
t-sql
reference
build-2024
system data types [SQL Server]
data types [SQL Server]
data types [SQL Server], about data types
TSQL
>=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric

Data types (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]

In the [!INCLUDE ssdenoversion-md], 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.

[!INCLUDE ssNoVersion] supplies a set of system data types that define all the types of data that can be used with [!INCLUDE ssNoVersion]. You can also define your own data types in [!INCLUDE tsql] or the [!INCLUDE msCoName] [!INCLUDE dnprdnshort]. Alias data types are based on the system-supplied data types. For more information about alias data types, see CREATE TYPE. User-defined types obtain their characteristics from the methods and operators of a class that you create by using one of the programming languages supported by the [!INCLUDE dnprdnshort].

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

  • The data type of the result is determined by applying the rules of data type precedence to the data types of the input expressions.

  • 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.

  • 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).

[!INCLUDE ssNoVersion] provides data type synonyms for ISO compatibility. For more information, see Data type synonyms.

For more specific information on data types in [!INCLUDE ssazuresynapse_md], see Table data types in Synapse SQL.

For more specific information on data types in [!INCLUDE fabric], see Data type.

Data type categories

Data types in [!INCLUDE ssNoVersion] are organized into the following categories:

In [!INCLUDE ssNoVersion], 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

1 The bit data type is used for storing Boolean values.

2 The decimal and numeric data types are identical.

Approximate numerics

Date and time

Character strings

Unicode character strings

Binary strings

Other data types

1 The geography and geometry data types are spatial types.

Related content