What is Work with data types

Columns and variables used in Transact-SQL each have a data type. The behavior of values in expressions depends on the data type of the column or variable being referenced. For example, as you saw previously, you can use the + operator to concatenate two string values, or to add two numeric values.

The following table shows common data types supported in a SQL Server database.

Exact Numeric

Approximate Numeric

Character

Date/Time

Binary

Other

tinyint

float

char

date

binary

cursor

smallint

real

varchar

time

varbinary

hierarchyid

int

text

datetime

image

sql_variant

bigint

nchar

datetime2

table

bit

nvarchar

smalldatetime

timestamp

decimal/numeric

ntext

datetimeoffset

uniqueidentifier

numeric

xml

money

geography

smallmoney

geometry

 Note

For more details on the different data types and their attributes, visit the Transact-SQL reference documentation.

Data type conversion

Compatible data type values can be implicitly converted as required. For example, suppose you can use the + operator to add an integer number to a decimal number, or to concatenate a fixed-length char value and a variable length varchar value. However, in some cases you may need to explicitly convert values from one data type to another – for example, trying to use + to concatenate a varchar value and a decimal value will result in an error, unless you first convert the numeric value to a compatible string data type.

Leave a Reply

Your email address will not be published. Required fields are marked *