In the previous article, you learned the basic SQL syntax, right?In this article, we will go over some of the data types in SQL.

Like other languages,SQLalso has its own data types.The SQL Data Type is an attribute that defines the type of data of any object.Each column, every variable, an expression has a related data type in SQL.You can use these data types to create tables or select the data types for the columns in the table based on your requirements.

SQL Server provides 6 types of data that you can use as listed below:

Data type Exact Numeric (number accurate, no error)

DatatypesStart fromCome
bigint-9,223,372,036,854,775,8089,223,372,036,854,775,807
int-2,147,483,6482,147,483,647
smallint-32.76832,767
tinyint0255
bit0first
decimal-10 ^ 38 +110 ^ 38 -1
numeric-10 ^ 38 +110 ^ 38 -1
money-922,337,203,685,477,5808+922,337,203,685,477.5807
smallmoney-214,748.3648+214,748.3647

Data Type Approximate Numeric

DatatypesStart fromCome
float-1.79E + 3081.79E + 308
real-3.40E + 383.40E + 38

Date and time data type in SQL

DatatypesStart fromCome
datetimeJohn 1, 1753Dec 31, 9999
smalldatetimeJan 1, 1900Jun 6, 2079
dateSave a date as June 30, 1991
timeKeep a time as 12:30 PM

Here, the datetime has a precision of 3.33 milliseconds, smalldatetime has a precision of one minute.

Character string data type

DatatypesDescribe
charMaximum length is 8000 characters.Non-Unicode characters fixed in fixed length.
varcharMaximum length is 8000 characters.(Non-Unicode data of custom length).
varchar (max)Maximum length is 231 characters, non-Unicode non-custom length (SQL Server 2005 only).
textNon-Unicode data of a custom length with a maximum length of 2,147,483,647 characters.

Character string data, containing Unicode

DatatypesDescribe
ncharUp to 4000 characters long.(Unicode characters of fixed length)
nvarcharUp to 4000 characters long.(Unicode characters of custom length)
nvarchar (max)Longest 231characters (only with SQL Server 2005).(Unicode characters of custom length)
ntextThe maximum length is 1,073,741,823 characters.(Unicode characters of custom length)

Binary data type

DatatypesDescribe
binaryMaximum length of 8,000 bytes (fixed length binary data)
varbinaryMaximum length of 8,000 bytes (Variable binary data)
varbinary (max)Long maximum 231 bytes (only on SQL Server 2005).(Variable binary data)
imageThe maximum length is 2,147,483,647 bytes.(Variable binary data)

Other SQL Data Types

DatatypesDescribe
sql_variantStores different types of data supported by SQL Server except text, ntext, and timestamp.
timestampStore a unique number in the database, which is updated every time the row is updated.
uniqueidentifier3Globally Unique Identifier (GUID)
xmlStoring XML data, you can save xml in columns or variables (only on SQL Server 2005).
cursorReference to a pointer object.
tableStore a result set for later processing.