What are Data Types?
Data types tell the database what kind of information you're storing. Just like you put clothes in a closet and food in a fridge - different data goes in different types.
The 4 Main Data Types
1. Numbers
INTEGER - Whole numbers (no decimals)
age INTEGER -- 20, 25, 30
student_id INTEGER -- 1, 2, 3DECIMAL - Numbers with decimals (for money!)
price DECIMAL(10,2) -- 19.99, 100.50
salary DECIMAL(10,2) -- 50000.002. Text
VARCHAR(size) - Text with max length
name VARCHAR(100) -- "John Smith"
email VARCHAR(200) -- "john@email.com"TEXT - Long text (no limit)
bio TEXT -- Long description
content TEXT -- Blog post3. Date & Time
birth_date DATE -- 2000-05-15
login_time TIME -- 09:30:00
created_at TIMESTAMP -- 2024-11-19 10:30:004. True/False
BOOLEAN - Yes or No values
is_active BOOLEAN -- TRUE or FALSE
is_verified BOOLEAN -- TRUE or FALSEQuick Guide: Which Type to Use?
Storing ages, counts, IDs? → INTEGER
Storing money or prices? → DECIMAL(10,2)
Storing names, emails? → VARCHAR(100)
Storing long text? → TEXT
Storing dates? → DATE or TIMESTAMP
Storing yes/no? → BOOLEAN
Real Example
CREATE TABLE users (
id INTEGER,
name VARCHAR(100),
email VARCHAR(200),
age INTEGER,
salary DECIMAL(10,2),
is_active BOOLEAN,
created_at TIMESTAMP
);Tip: Always use DECIMAL for money (not FLOAT) - it's more accurate!
See Data Types in Action
name is VARCHAR (text), age is INTEGER (number), grade is CHAR (single letter)
Click "Run Query" to see results