Common Data Types
Introduction to SQL
Database
SQL Basics
Creating a Database
Using a Database
Creating a Table
Common Data Types
Inserting Data
Selecting Data
WHERE Clause
Comparison Operators
AND, OR, and NOT
ORDER BY Clause
LIMIT Clause
DISTINCT
LIKE Operator
IN, BETWEEN, and IS NULL
Updating Data
Deleting Data
ALTER TABLE
DROP TABLE
PRIMARY KEY and NOT NULL
FOREIGN KEY and Relationships
Aggregate Functions
GROUP BY Clause
HAVING Clause
JOIN Basics
INNER JOIN
LEFT JOIN
Aliases
Subqueries
Indexes
User Permissions and Security
Common Mistakes Beginners Make
Practice Ideas
Common Data Types
Common SQL Data Types
Definition: A data type is a label that tells the database what kind of information to expect in a specific column. Every column in a SQL table must have a defined data type.
Why: Beginner tutorials focus on these core types because they cover 90% of everyday data needs. Using the correct data type ensures data integrity, saves storage space, and allows the database to perform mathematical operations or date calculations correctly.
Most Common Data Types
Below are the foundational data types you will encounter in almost every SQL database:
| Category | Data Type | Description & Usage |
|---|---|---|
| Numeric | INT |
Stores whole numbers (integers) without decimals. Used for IDs, ages, and quantities. |
| Text | VARCHAR(size) |
Stores variable-length text. The "size" represents the maximum number of characters (e.g., VARCHAR(255)). |
| Numeric | DECIMAL(p,s) |
Used for exact numbers with decimals, like money or percentages. p is the total digits, s is digits after the decimal. |
| Temporal | DATE |
Stores dates in the format YYYY-MM-DD. Used for birthdays, order dates, or deadlines. |
| Boolean | BOOLEAN |
Stores TRUE or FALSE values. Used for flags like "is_active" or "has_paid". |
Key Notes
- VARCHAR vs. CHAR:
VARCHARonly uses the space needed for the text you enter, whileCHARuses a fixed amount of space even if the text is shorter.VARCHARis generally preferred for names and descriptions. - Precision Matters: Choosing
INTwhen you actually need decimals (like 19.99) will cause the database to round your numbers, leading to data errors. - Database Variation: While these types are standard, some databases have slightly different names (e.g.,
TEXTin some systems is used for very long descriptions instead ofVARCHAR).
🏋️ Test Yourself With Exercises
Take our quiz on Common Data Types to test your knowledge.
Browse Quizzes »