SQL Data Types
In SQL, each column must be assigned a data type that defines the kind of data it can store, such as integers, dates, text, or binary values. Choosing the correct data type is crucial for data integrity, query performance and efficient indexing.
Benefits of using the right data type:
- Memory-efficient storage
- Accurate operations (e.g., calculations, sorting)
- Consistency in stored values
- Validation of input data
SQL data types are broadly categorized into several groups:

1. Numeric Data Types
Numeric data types are fundamental to database design and are used to store numbers, whether they are integers, decimals or floating-point numbers. These data types allow for mathematical operations like addition, subtraction, multiplication and division, which makes them essential for managing financial, scientific and analytical data.
Exact Numeric Datatype
Exact numeric types are used when precise numeric values are needed, such as for financial data, quantities, and counts. Some common exact numeric types include:
Data Type | Description | Range |
---|---|---|
BIGINT | Large integer numbers | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
INT | Standard integer values | -2,147,483,648 to 2,147,483,647 |
SMALLINT | Small integers | -32,768 to 32,767 |
TINYINT | Very small integers | 0 to 255 |
DECIMAL | Exact fixed-point numbers (e.g., for financial values) | -10^38 + 1 to 10^38 - 1 |
NUMERIC | Similar to DECIMAL, used for precision data | -10^38 + 1 to 10^38 - 1 |
MONEY | For storing monetary values | -922,337,203,685,477.5808 to 922,337,203,685,477.5807 |
SMALLMONEY | Smaller monetary values | -214,748.3648 to 214,748.3647 |
Approximate Numeric Datatype
These types are used to store approximate values, such as scientific measurements or large ranges of data that don't need exact precision.
Data Type | Description | Range |
---|---|---|
FLOAT | Approximate numeric values | -1.79E+308 to 1.79E+308 |
REAL | Similar to FLOAT, but with less precision | -3.40E+38 to 3.40E+38 |
2. Character and String Data Types
Character data types are used to store text or character-based data. The choice between fixed-length and variable-length data types depends on the nature of your data.
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 2^31 - 1 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 Data Types
Unicode data types are used to store characters from any language, supporting a wider variety of characters. These 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 2^31 - 1 characters(SQL Server 2005 only). (Variable Length Unicode data) |
3. Date and Time Data Type
SQL provides several data types for storing date and time information. They are essential for managing timestamps, events and time-based queries. These are given in the below table.
Data Type | Description | Storage Size |
---|---|---|
DATE | stores the data of date (year, month, day) | 3 Bytes |
TIME | stores the data of time (hour, minute,second) | 3 Bytes |
DATETIME | store both the data and time (year, month, day, hour, minute, second) | 8 Bytes |
4. Binary Data Types in SQL
Binary data types are used to store binary data such as images, videos or other file types. These include:
Data Type | Description | Max Length |
---|---|---|
Binary | Fixed-length binary data. | 8000 bytes |
VarBinary | Variable-length binary data. | 8000 bytes |
Image | Stores binary data as images. | 2,147,483,647 bytes |
5. Boolean Data Type in SQL
The BOOLEAN data types are used to store logical values, typically TRUE or FALSE. It is commonly used for flag fields or binary conditions.
6. Special Data Types
SQL also supports some specialized data types for advanced use cases:
- XML Data Type: Used to store XML data and manipulate XML structures in the database
- Spatial Data Type (Geometry): stores planar spatial data, such as points, lines, and polygons, in a database table.