SQL Notes
Learn SQL data types, their categories, practical examples, storage considerations, and best practices for choosing the correct data type in database design.
When you create a database table, one of the biggest decisions is picking the right data type for each column.
A data type tells the database what kind of info goes in that column. It's like the rules of the game—controls how data gets stored, validated, and processed.
Think about it: a person's name is text. Their age is a number. Storing both the same way makes no sense because they're different things.
SQL data types keep your data accurate, make queries faster, save storage space, and stop garbage from getting into your database.
In this lesson, you'll learn what data types are, why they matter, what types exist, and how to pick the right one for your tables.
Why Are Data Types Important?
A lot of beginners just pick a data type and move on.
But picking the wrong type causes *real* problems later.
Good data types:
Improve Data Accuracy
Stop bad values from sneaking in.
Save Storage Space
Use only what you need.
Increase Performance
Queries run faster with efficient storage.
Simplify Validation
The database checks automatically.
Improve Database Design
Well-designed tables are easier to maintain and scale.
Categories of SQL Data Types
Most SQL databases organize types into buckets:
- Numeric Data Types
- Character/String Data Types
- Date and Time Data Types
- Boolean Data Types
- Binary Data Types
Let's go through each.
Numeric Data Types
Numeric types store numbers. You use them for:
- IDs
- Prices
- Quantities
- Salaries
- Scores
- Measurements
INT (Integer)
Stores whole numbers.
Example:
CREATE TABLE Students (
StudentID INT
);Valid values:
1 100 5000 99999
Invalid values:
10.5 Hello ABC
Common uses:
- Student IDs
- Employee IDs
- Order Numbers
BIGINT
Stores huge whole numbers (bigger than INT).
Example:
BIGINTUse it when values get *really* large:
- Population databases
- Financial systems
- Large transaction systems
SMALLINT
Stores smaller integer values.
Example:
SMALLINTUseful when:
- Storage optimization matters
- Values stay in a limited range
Examples:
- Age
- Rating Scores
- Small Counters
DECIMAL
Stores exact numbers with decimals.
Example:
DECIMAL(10,2)Meaning:
10 → Total digits
2 → Decimal placesValid examples:
199.99 5000.50 45.75
Common uses:
- Prices
- Salaries
- Banking systems
FLOAT
Stores approximate decimal values.
Example:
FLOATUsed for:
- Scientific calculations
- Measurements
- Statistical data
⚠️ FLOAT can introduce rounding errors. For money? Use DECIMAL instead.
Character and String Data Types
String types store text:
- Names
- Addresses
- Emails
- Product descriptions
CHAR
Stores fixed-length text.
Example:
CHAR(10)If your value is less than 10 characters, it still reserves 10 spots.
Example:
ABC
still takes up 10 character positions.
Common uses:
- Country codes
- Gender values
- Fixed identifiers
VARCHAR
Stores variable-length text.
Example:
VARCHAR(100)A value uses only the space it needs.
Examples:
Rahul Priya Amit Kumar
Most modern apps use VARCHAR everywhere.
Common uses:
- Names
- Emails
- Cities
- Product Names
TEXT
Stores *lots* of text.
Example:
TEXTCommon uses:
- Blog articles
- Product descriptions
- User comments
- Documentation
Date and Time Data Types
Apps need to store dates and times:
- Birth Dates
- Order Dates
- Login Times
- Event Schedules
SQL has specialized types for this.
DATE
Stores just a date.
Example:
DATESample value:
2026-08-15
Common uses:
- Birth dates
- Joining dates
- Event dates
TIME
Stores just time.
Example:
TIMESample value:
14:30:45
Useful for:
- Shift schedules
- Appointment times
- Timetables
DATETIME
Stores both date and time.
Example:
DATETIMESample value:
2026-08-15 14:30:45
Used everywhere in business apps.
TIMESTAMP
Stores date and time, often auto-updating.
Example:
TIMESTAMPCommon uses:
- Record creation time
- Last update tracking
- Activity logs
Boolean Data Types
Boolean values are true or false.
Example:
BOOLEANPossible values:
TRUE FALSE
Apps use booleans for:
- Active users
- Completed tasks
- Email verification
- Subscription status
Example:
IsActive BOOLEANBinary Data Types
Binary types store raw binary data:
- Images
- Audio files
- Documents
- Videos
BLOB
BLOB = Binary Large Object.
Example:
BLOBUse it when storing binary content directly in your database. Though honestly, most modern apps store files separately and just save the path.
Data Types in a Real Table
Look at an employee table:
CREATE TABLE Employees (
EmployeeID INT,
FullName VARCHAR(100),
Salary DECIMAL(10,2),
DateOfJoining DATE,
IsActive BOOLEAN
);Each column uses a different type based on what it stores.
This creates an efficient, organized database.
Choosing the Correct Data Type
Picking the right data type is fundamental to good database design.
Ask yourself:
Is the value numeric?
Use:
INT DECIMAL FLOAT
Is the value text?
Use:
CHAR
VARCHAR
TEXTIs the value a date?
Use:
DATE
DATETIME
TIMESTAMPIs the value true or false?
Use:
BOOLEANThe goal: pick the best fit without wasting storage.
Common Beginner Mistakes
Using VARCHAR for Everything
Bad:
Age VARCHAR(50)Good:
Age INTNumbers should use numeric types.
Using FLOAT for Money
Bad:
Salary FLOATGood:
Salary DECIMAL(10,2)DECIMAL gives you precision.
Using Large Data Types Unnecessarily
Avoid:
Name TEXTwhen:
Name VARCHAR(100)works fine.
Pick the smallest practical type.
Best Practices
Use Appropriate Data Types
Match the type to your actual data.
Avoid Excessive Lengths
Don't use:
VARCHAR(5000)for a first name field.
Use DECIMAL for Financial Data
Accuracy matters.
Use DATE Types for Dates
Don't store dates as plain text.
Plan for Future Growth
Think about how data might expand.
Summary
SQL data types define what kind of data goes in a column. They're crucial for database design because they keep your data accurate, make queries faster, save storage, and maintain 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 picking types
Picking the right data type is foundational to 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 Complete Guide topic.
Search Terms
sql-complete-guide, sql complete guide, sql, complete, guide, basics, data, types
Related SQL Complete Guide Topics