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)

Datatypes Start from Come
bigint -9,223,372,036,854,775,808 9,223,372,036,854,775,807
int -2,147,483,648 2,147,483,647
smallint -32.768 32,767
tinyint 0 255
bit 0 first
decimal -10 ^ 38 +1 10 ^ 38 -1
numeric -10 ^ 38 +1 10 ^ 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

Datatypes Start from Come
float -1.79E + 308 1.79E + 308
real -3.40E + 38 3.40E + 38

Date and time data type in SQL

Datatypes Start from Come
datetime John 1, 1753 Dec 31, 9999
smalldatetime Jan 1, 1900 Jun 6, 2079
date Save a date as June 30, 1991
time Keep 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

Datatypes Describe
char Maximum length is 8000 characters.Non-Unicode characters fixed in fixed length.
varchar Maximum 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).
text Non-Unicode data of a custom length with a maximum length of 2,147,483,647 characters.

Character string data, containing Unicode

Datatypes Describe
nchar Up to 4000 characters long.(Unicode characters of fixed length)
nvarchar Up to 4000 characters long.(Unicode characters of custom length)
nvarchar (max) Longest 231characters (only with SQL Server 2005).(Unicode characters of custom length)
ntext The maximum length is 1,073,741,823 characters.(Unicode characters of custom length)

Binary data type

Datatypes Describe
binary Maximum length of 8,000 bytes (fixed length binary data)
varbinary Maximum length of 8,000 bytes (Variable binary data)
varbinary (max) Long maximum 231 bytes (only on SQL Server 2005).(Variable binary data)
image The maximum length is 2,147,483,647 bytes.(Variable binary data)

Other SQL Data Types

Datatypes Describe
sql_variant Stores different types of data supported by SQL Server except text, ntext, and timestamp.
timestamp Store a unique number in the database, which is updated every time the row is updated.
uniqueidentifier3 Globally Unique Identifier (GUID)
xml Storing XML data, you can save xml in columns or variables (only on SQL Server 2005).
cursor Reference to a pointer object.
table Store a result set for later processing.


Leave a Comment