SQL Topics
SQL Data Types
title: SQL Data Types
When creating a database table, one of the most important decisions is choosing the correct data type for each column.
A data type tells the database what kind of information can be stored in a particular column. It acts as a set of rules that controls how data is stored, validated, and processed.
For example, a person's name contains text, while their age contains numbers. Storing both values using the same data type would not make sense because they represent different kinds of information.
SQL data types help maintain data accuracy, improve performance, reduce storage usage, and prevent invalid information from being inserted into the database.
In this lesson, you will learn what SQL data types are, why they matter, the different categories of data types, and how to choose the most appropriate type for your database tables.
What is a Data Type?
A data type defines the type of value a column can store.
Think of a table containing student information.
| StudentID | Name | Age |
|---|---|---|
| 1 | Rahul | 20 |
| 2 | Priya | 21 |
Here:
- StudentID stores numbers.
- Name stores text.
- Age stores numbers.
Each column requires a suitable data type.
Example:
CREATE TABLE Students (
StudentID INT,
Name VARCHAR(100),
Age INT
);The database now understands what kind of information each column should contain.
Why Are Data Types Important?
Many beginners select data types without much thought.
However, choosing the wrong data type can create serious problems later.
Proper data types help:
Improve Data Accuracy
Prevent invalid values from being stored.
Save Storage Space
Use only the storage required for the data.
Increase Performance
Queries run faster when data is stored efficiently.
Simplify Validation
The database automatically checks data compatibility.
Improve Database Design
Well-designed tables are easier to maintain and scale.
Categories of SQL Data Types
Most SQL database systems organize data types into several major categories:
- Numeric Data Types
- Character/String Data Types
- Date and Time Data Types
- Boolean Data Types
- Binary Data Types
Let's examine each category in detail.
Numeric Data Types
Numeric data types store numbers.
They are used for:
- IDs
- Prices
- Quantities
- Salaries
- Scores
- Measurements
INT (Integer)
The INT data type stores whole numbers.
Example:
CREATE TABLE Students (
StudentID INT
);Valid values:
1
100
5000
99999Invalid values:
10.5
Hello
ABCCommon uses:
- Student IDs
- Employee IDs
- Order Numbers
BIGINT
BIGINT stores much larger whole numbers than INT.
Example:
BIGINTUsed when values may become extremely large.
Examples:
- Population databases
- Financial systems
- Large transaction systems
SMALLINT
SMALLINT stores smaller integer values.
Example:
SMALLINTUseful when:
- Storage optimization matters
- Values remain within a limited range
Examples:
- Age
- Rating Scores
- Small Counters
DECIMAL
DECIMAL stores exact numeric values including decimal places.
Example:
DECIMAL(10,2)Meaning:
10 → Total digits
2 → Decimal placesValid examples:
199.99
5000.50
45.75Common uses:
- Prices
- Salaries
- Banking systems
FLOAT
FLOAT stores approximate decimal values.
Example:
FLOATUsed for:
- Scientific calculations
- Measurements
- Statistical data
Because FLOAT may introduce rounding differences, financial systems generally prefer DECIMAL.
Character and String Data Types
String data types store text.
Examples:
- Names
- Addresses
- Emails
- Product descriptions
CHAR
CHAR stores fixed-length text.
Example:
CHAR(10)If the value contains fewer than 10 characters, the remaining space is reserved.
Example:
ABCmay still occupy 10 character positions.
Common uses:
- Country codes
- Gender values
- Fixed identifiers
VARCHAR
VARCHAR stores variable-length text.
Example:
VARCHAR(100)A value uses only the space it actually requires.
Examples:
Rahul
Priya
Amit KumarMost modern applications use VARCHAR extensively.
Common uses:
- Names
- Emails
- Cities
- Product Names
TEXT
TEXT stores large amounts of text.
Example:
TEXTCommon uses:
- Blog articles
- Product descriptions
- User comments
- Documentation
Date and Time Data Types
Applications often need to store dates and times.
Examples:
- Birth Dates
- Order Dates
- Login Times
- Event Schedules
SQL provides specialized data types for this purpose.
DATE
Stores only a date.
Example:
DATESample value:
2026-08-15Common uses:
- Birth dates
- Joining dates
- Event dates
TIME
Stores only time.
Example:
TIMESample value:
14:30:45Useful for:
- Shift schedules
- Appointment times
- Timetables
DATETIME
Stores both date and time.
Example:
DATETIMESample value:
2026-08-15 14:30:45Used extensively in business applications.
TIMESTAMP
Stores date and time information, often with automatic update capabilities.
Example:
TIMESTAMPCommon uses:
- Record creation time
- Last update tracking
- Activity logs
Boolean Data Types
Boolean values represent logical states.
Example:
BOOLEANPossible values:
TRUE
FALSEApplications use Boolean fields for:
- Active users
- Completed tasks
- Email verification
- Subscription status
Example:
IsActive BOOLEANBinary Data Types
Binary types store raw binary information.
Examples:
- Images
- Audio files
- Documents
- Videos
BLOB
BLOB stands for Binary Large Object.
Example:
BLOBUsed when storing binary content directly inside a database.
However, many modern applications store files separately and save only file paths inside the database.
Data Types in a Real Table
Consider an employee table:
CREATE TABLE Employees (
EmployeeID INT,
FullName VARCHAR(100),
Salary DECIMAL(10,2),
DateOfJoining DATE,
IsActive BOOLEAN
);Each column uses a different data type based on the nature of its data.
This creates an efficient and organized database structure.
Choosing the Correct Data Type
Selecting appropriate data types is a critical database design skill.
Consider the following questions:
Is the value numeric?
Use:
INT
DECIMAL
FLOATIs the value text?
Use:
CHAR
VARCHAR
TEXTIs the value a date?
Use:
DATE
DATETIME
TIMESTAMPIs the value true or false?
Use:
BOOLEANThe goal is to choose the most suitable type without wasting storage.
Common Beginner Mistakes
Using VARCHAR for Everything
Poor design:
Age VARCHAR(50)Better:
Age INTNumeric values should use numeric types.
Using FLOAT for Money
Poor choice:
Salary FLOATBetter:
Salary DECIMAL(10,2)DECIMAL provides higher precision.
Using Large Data Types Unnecessarily
Avoid:
Name TEXTwhen:
Name VARCHAR(100)is sufficient.
Choose the smallest practical type.
Best Practices
Use Appropriate Data Types
Match the type to the actual data.
Avoid Excessive Lengths
Do not use:
VARCHAR(5000)for a first name field.
Use DECIMAL for Financial Data
Accuracy is important in financial applications.
Use DATE Types for Dates
Avoid storing dates as plain text.
Plan for Future Growth
Consider how data may expand over time.
Summary
SQL data types define the kind of information that can be stored in a column. They play a crucial role in database design by ensuring accuracy, improving performance, reducing storage usage, and maintaining data integrity.
In this lesson, you learned:
- What data types are
- Why data types matter
- Numeric data types
- String data types
- Date and time data types
- Boolean data types
- Binary data types
- Best practices for selecting data types
Choosing the correct data type is one of the foundations of professional database design.
Next Step
Continue to the next lesson:
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for SQL Data Types.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this SQL topic.
Search Terms
sql, sql complete guide, sql tutorial, sql notes, complete, guide, basics, data
Related SQL Topics