0% found this document useful (0 votes)
11 views

Handout1 DataTypeMSSQL

In SQL Server, each column, variable, expression, and parameter has a data type that specifies what type of data it can hold, such as integers, strings, dates, etc. There are exact numeric, approximate numeric, character string, Unicode character string, binary string, and other data types. When expressions with different data types are combined, the result's data type and other properties depend on precedence rules for data type, collation, precision, scale, and length.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Handout1 DataTypeMSSQL

In SQL Server, each column, variable, expression, and parameter has a data type that specifies what type of data it can hold, such as integers, strings, dates, etc. There are exact numeric, approximate numeric, character string, Unicode character string, binary string, and other data types. When expressions with different data types are combined, the result's data type and other properties depend on precedence rules for data type, collation, precision, scale, and length.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

8/12/23, 8:52 PM Data types (Transact-SQL) - SQL Server | Microsoft Learn

Data types (Transact-SQL)


Article • 05/23/2023

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW) Warehouse in Microsoft Fabric

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

7 Note

For more specific information on data types in Azure Synapse Analytics, see Table data types in Synapse SQL. For more specific information on data types in Microsoft Fabric, see Data type.

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

7 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

https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver16 1/3
8/12/23, 8:52 PM Data types (Transact-SQL) - SQL Server | Microsoft Learn

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

See also
CREATE PROCEDURE (Transact-SQL)
CREATE TABLE (Transact-SQL)
DECLARE @local_variable (Transact-SQL) EXECUTE (Transact-SQL)
Expressions (Transact-SQL)
Functions (Transact-SQL)
LIKE (Transact-SQL)
sp_droptype (Transact-SQL)

https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver16 2/3
8/12/23, 8:52 PM Data types (Transact-SQL) - SQL Server | Microsoft Learn
sp_help (Transact-SQL)
sp_rename (Transact-SQL)

https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver16 3/3

You might also like