Data types (Transact-SQL)

APPLIES TO: yesSQL Server (starting with 2008) yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel 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 charvarchartextncharnvarchar, 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 numericsUnicode character strings
Approximate numericsBinary strings
Date and timeOther 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: textntextimagevarbinary(max), and xml

     Note

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

Exact numerics

  
bigintnumeric
bitsmallint
decimalsmallmoney
inttinyint
money 

Approximate numerics

  
floatreal

Date and time

  
datedatetimeoffset
datetime2smalldatetime
datetimetime

Character strings

  
charvarchar
text 

Unicode character strings

  
ncharnvarchar
ntext 

Binary strings

  
binaryvarbinary
image 

Other data types

  
cursorrowversion
hierarchyiduniqueidentifier
sql_variantxml
Spatial Geometry TypesSpatial Geography Types
table
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值