(because age ain’t text, and names aren’t numbers)
Let’s say we’re building a users
table like this:
id | name | age | balance | signup_date | is_active | |
---|---|---|---|---|---|---|
1 | Olivia | olivia@email.com | 26 | 99.50 | 2024-09-20 | TRUE |
2 | Mason | mason@mail.com | 30 | 199.99 | 2023-07-12 | FALSE |
You’re planning this table and asking:
“What kind of stuff is going in each column?”
That’s where SQL data types come in. You’re telling the database:
- This column = text
- That one = number
- This other one = date
- And that = true/false
Based on that, here’s how we’d define the table:
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
email VARCHAR(100),
age INT,
balance DECIMAL(10,2),
signup_date DATE,
is_active BOOLEAN
);
Numeric Data Types
Type | What it stores | Example |
---|---|---|
INT | Whole numbers | 1, 42, -10 |
BIGINT | Large numbers | 9000000000 |
FLOAT | Decimals (approximate) | 3.14 |
DECIMAL(p,s) | Exact decimals (like money) | 99.99, 123.45 |
Use:
INT
for age, quantity, IDsDECIMAL
for money, pricingFLOAT
for averages or measurements
Text Data Types
Type | What it stores | Example |
---|---|---|
VARCHAR(n) | Variable text (max n chars) | ‘Mason’, ‘Olivia’ |
CHAR(n) | Fixed-length text | ‘Y’, ‘NY’ |
TEXT | Long text | Messages, bios |
Use:
VARCHAR
for names, emails, citiesTEXT
for comments, articlesCHAR
for codes (like ‘M’ or ‘F’)
Date & Time Data Types
Type | Stores… | Example |
---|---|---|
DATE | Just the date | ‘2025-04-03’ |
TIME | Just the time | ’14:30:00′ |
DATETIME | Full date & time | ‘2025-04-03 14:30:00’ |
TIMESTAMP | With time zone stuff | Used in logs |
Use:
DATE
for birthdays, hire datesDATETIME
for events, signupsTIMESTAMP
for time zone-sensitive tracking
Boolean Type
Type | Stores… | Values |
---|---|---|
BOOLEAN / BOOL | True/False | 1 (TRUE), 0 (FALSE) |
Use:
is_active
,is_deleted
,is_verified
— anything yes/no
Recap
- Choose your data types based on the real kind of data you’re storing
- Use
INT
for whole numbers,DECIMAL
for money VARCHAR
for most text,DATE
for calendar thingsBOOLEAN
for anything binary (yes/no)
Good data types = cleaner data + faster queries + less stress later
Next up:
Let’s see how you can find (aka filter) specific stuff in your table — like “users over 21” or “all active accounts.”
This is where the WHERE
clause comes in. If you want a simple intro to filtering data in SQL, check out this
beginner-friendly guide.
I’ll break it down in plain English next!