SQL Data Types
SQL data types tutorial with examples for beginners
SQL Data Types define the type of data a column can store inside a database table. Choosing the correct data type is one of the most important steps in database design because it affects:
Storage space
Query performance
Data accuracy
Validation and integrity
In this beginner-friendly SQL tutorial, you’ll learn:
What SQL data types are
Common data types in SQL (string, numeric, date/time, etc.)
MySQL-specific data types
Best practices for selecting the right data type
Real-world examples
Every column in a table must be assigned a data type. A data type tells the database:
What kind of data the column will store
How much space it will consume
How it behaves in queries
Example:
CREATE TABLE users (
id INT,
name VARCHAR(100),
created_at DATETIME
);
Here:
INT → stores numbers
VARCHAR(100) → stores text up to 100 characters
DATETIME → stores date and time values
SQL data types fall under these main categories:
String / Character Types
Numeric Types (Integer & Decimal)
Date & Time Types
Boolean Type
Binary Types
JSON & Special Types (DB-specific)
Let's explore each with examples.
Used to store text values.
| Data Type | Description | Example |
|---|---|---|
CHAR(n) |
Fixed-length string | CHAR(10) |
VARCHAR(n) |
Variable-length string | VARCHAR(255) |
TEXT |
Long text | Article content |
ENUM |
Predefined values | ENUM('Male','Female') |
name VARCHAR(100),
city CHAR(20),
bio TEXT
Used to store integer and decimal values.
| Type | Range |
|---|---|
TINYINT |
-128 to 127 |
INT |
-2147483648 to 2147483647 |
BIGINT |
Very large numbers |
| Type | Description |
|---|---|
DECIMAL(a,b) |
Exact fixed-point numbers |
FLOAT |
Approximate floating numbers |
DOUBLE |
Double-precision floating numbers |
age INT,
salary DECIMAL(10,2),
rating FLOAT(4,2)
Used to store date, time, or both.
| Type | Description |
|---|---|
DATE |
YYYY-MM-DD |
TIME |
HH:MM:SS |
DATETIME |
Date & time |
TIMESTAMP |
Stores Unix timestamp (auto updates) |
created_at DATETIME,
login_time TIMESTAMP
Most SQL databases store boolean values as:
BOOLEAN or TINYINT(1)
Example:
is_active BOOLEAN
Used for storing files and encrypted data.
| Type | Description |
|---|---|
BLOB |
Binary Large Object |
BINARY |
Fixed-length binary |
VARBINARY |
Variable-length binary |
profile_image BLOB
Modern databases like MySQL, PostgreSQL, and SQL Server support JSON.
preferences JSON
This allows storing structured key-value data.
MySQL includes unique types such as:
ENUM – Predefined set of values
gender ENUM('Male','Female','Other')
SET – Multiple values from a list
hobbies SET('Reading','Gaming','Traveling')
If age fits in TINYINT, don’t use INT.
Faster and more index-friendly.
Avoid floating-point rounding issues.
Useful for automatic CURRENT_TIMESTAMP values.
Easy validation and storage.
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(150),
age TINYINT,
salary DECIMAL(10,2),
join_date DATE,
is_active BOOLEAN,
profile BLOB
);
In this SQL Data Types tutorial, you learned:
What SQL data types are
Different categories of data types
MySQL-specific data types
Best practices for choosing the right type
Real-world examples
Choosing the correct data type improves performance, saves storage, and ensures data accuracy in your database.