Open In App

SQL Data Types

Last Updated : 24 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

A column’s data type is essentially the type of data format that will be used to store the data in each cell; examples include any type of integer, character, money, date and time, binary, etc. We’ll acquire in-depth information about SQL Data Types in this tutorial.

SQL Data Types

An SQL developer must know what data type will be stored inside each column while creating a table. The data type guideline for SQL is to understand what type of data is expected inside each column and it also identifies how SQL will interact with the stored data.

For every database, data types are primarily classified into three categories.

  • Numeric Datatypes
  • Date and Time Datatypes
  • String Datatypes

Like in other programming languages, SQL also has certain datatypes available. A brief idea of all the datatypes is discussed below.

Numeric Data Types in MYSQL

Exact Numeric Datatype

There are nine subtypes which are given below in the table. The table contains the range of data in a particular type. 

Data Type

From 

To

BigInt

-263 (-9,223,372,036,854,775,808)

263 -1 (9,223,372,036,854,775,807)

Int

-231 (-2,147,483,648)

231-1 (2,147,483,647)

smallint

-215 (-32,768)

215-1 (32,767)

tinyint

0

28-1 (255)

bit

0

1

decimal

-1038+1

1038-1

numeric

-1038+1

1038-1

money 

-922,337,203,685,477.5808

922,337,203,685,477.5807

smallmoney

-214,748.3648

214,748.3647

Approximate Numeric Datatype

The subtypes of this datatype are given in the table with the range. 

Data Type From To

Float

-1.79E+308

1.79E+308

Real

-3.40E+38

3.40E+38

String Data Types in MYSQL

Character String Datatype

The subtypes are given in below table – 

Data Type Description

char

The maximum length of 8000 characters.(Fixed-Length non-Unicode Characters)

varchar

The maximum length of 8000 characters.(Variable-Length non-Unicode Characters)

varchar(max)

The maximum length of 231 characters(SQL Server 2005 only).(Variable Length non-Unicode data)

text

The maximum length of 2,127,483,647 characters(Variable Length non-Unicode data)

Unicode Character String Datatype

The details are given in below table – 

Data Type

Description

nchar

The maximum length of 4000 characters(Fixed-Length Unicode Characters)

Nvarchar

The maximum length of 4000 characters.(Variable-Length Unicode Characters)

nvarchar(max)

The maximum length of 231 characters(SQL Server 2005 only).(Variable Length Unicode data)

Server String Data Type in SQL

There are four subtypes of this datatype which are given below:

Datatypes

Description

Binary

The maximum length of 8000 bytes(Fixed-Length binary data)

varbinary

The maximum length of 8000 bytes(Variable Length binary data)

varbinary(max)

The maximum length of 231 bytes(SQL Server 2005 only).(Variable Length binary data)

text

Maximum Length of 2,147,483,647 bytes(Variable Length binary data)

Server Date and Time Data Type in SQL

The details are given in the below table.

Data Type Description

DATE

A data type is used to store the data of date in a record 

TIME

A data type is used to store the data of time in a record

DATETIME

A data type is used to store both the data,date, and time in the record.

Other Data Types

XML Datatype

XML data type allows storage of XML documents and fragments in a SQL Server database

DataType

Description

XML Datatype

A Datatype used to store data in the format of XML datatype

Spatial Dataype

A datatype is used for storing planar spatial data, such as points, lines, and polygons, in a database table.

DataType

Description

Geometry

A datatype is used for storing planar spatial data, such as points, lines, and polygons, in a database table.

Array Datatype

SQL Server does not have a built-in array datatype. However, it is possible to simulate arrays using tables or XML data types.

This text discusses the properties of data types in MYSQL.

SQL data types define the type of data that can be stored in a database column or variable. Here are the most common SQL data types:

Datatype

Properties

Numeric data types

These are used to store numeric values. Examples include INT, BIGINT, DECIMAL, and FLOAT.

Character data types

These are used to store character strings. Examples include CHAR, VARCHAR, and TEXT.

Date and time data types

These are used to store date and time values. Examples include DATE, TIME, and TIMESTAMP

Binary data types

These are used to store binary data, such as images or audio files. Examples include BLOB and BYTEA.

Boolean data type

This data type is used to store logical values. The only possible values are TRUE and FALSE.

Interval data types

These are used to store intervals of time. Examples include INTERVAL YEAR, INTERVAL MONTH, and INTERVAL DAY.

Array data types

These are used to store arrays of values. Examples include ARRAY and JSON.

XML data type

This data type is used to store XML data.

Spatial data types

These are used to store geometric or geographic data. Examples include POINT, LINE, and POLYGON.

Different databases may have different variations of these data types, or they may have additional data types not listed here. Understanding SQL data types are important for creating tables and working with data in a database, as it affects how data is stored and processed.



Previous Article
Next Article

Similar Reads

Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
Configure SQL Jobs in SQL Server using T-SQL
In this article, we will learn how to configure SQL jobs in SQL Server using T-SQL. Also, we will discuss the parameters of SQL jobs in SQL Server using T-SQL in detail. Let's discuss it one by one. Introduction :SQL Server Agent is a component used for database task automation. For Example, If we need to perform index maintenance on Production ser
7 min read
SQL vs NO SQL vs NEW SQL
SQL stands for Structured Query Language. Which is based on relational algebra and schema is fixed in this which means data is stored in the form of columns and tables. SQL follows ACID properties which means Atomicity, Consistency, Isolation, and Durability are maintained. There are three types of languages present in SQL : Data Definition Languag
2 min read
How to Convert Data From SQL to C Data Types?
At the point when an application calls SQLExecute or SQLExecDirect, the driver recovers the data for any boundaries bound with SQLBindParameter from capacity areas in the application. At the point when an application calls SQLSetPos, the driver recovers the data for an update or adds activity from sections bound with SQLBindCol. For data-at-executi
6 min read
Numeric and Date-time data types in SQL Server
MS SQL Server supports a wide range of data types. There are a few more important data types that are included in the article. In this article, we will cover numeric SQL server data types and different date-time data types. Let’s discuss one by one. bit : A bit is the smallest unit of a computer system. A bit can be either 0 or 1. The bit datatype
3 min read
SQL SERVER – Input and Output Parameter For Dynamic SQL
An Input Parameter can influence the subset of rows it returns from a select statement within it. A calling script can get the value of an output parameter. An aggregate function or any computational expression within the stored process can be used to determine the value of the output parameter. A parameter whose value is given into a stored proced
3 min read
Difference between T-SQL and PL-SQL
1. Transact SQL (T-SQL) : T-SQL is an abbreviation for Transact Structure Query Language. It is a product by Microsoft and is an extension of SQL Language which is used to interact with relational databases. It is considered to perform best with Microsoft SQL servers. T-SQL statements are used to perform the transactions to the databases. T-SQL has
3 min read
Difference between SQL and T-SQL
1. Structured Query language (SQL): A structured Query language is a computer language for a relational database system. Relational database system like MySQL oracle Sybase Informix uses SQL as standard database language for storing retrieving manipulating data and store in a relational database. Here are some SQL commands that are used for communi
3 min read
SQL Server | Convert tables in T-SQL into XML
In this, we will focus on how tables will be converted in T-SQL into XML in SQL server. And you will be able to understand how you can convert it with the help of command. Let's discuss it one by one. Overview :XML (Extensible Markup Language) is a markup language similar to HTML which was designed to share information between different platforms.
2 min read
SQL - SELECT from Multiple Tables with MS SQL Server
In SQL we can retrieve data from multiple tables also by using SELECT with multiple tables which actually results in CROSS JOIN of all the tables. The resulting table occurring from CROSS JOIN of two contains all the row combinations of the 2nd table which is a Cartesian product of tables. If we consider table1 contains m rows and table2 contains n
3 min read
Article Tags :