SQL Data Types
Every column has a data type that defines what kind of data it can hold.
Numeric types
| Type | Stores |
|---|
| int | whole numbers (e.g. -2, 0, 42) |
| decimal(p,s) | exact decimals (p = total digits, s = decimals after point) |
| float | approximate decimals |
| bigint | very large whole numbers |
String types
| Type | Stores |
|---|
| char(n) | fixed-length text (always n chars) |
| varchar(n) | variable-length text up to n chars |
| text | long text |
Date and time types
| Type | Stores |
|---|
| date | date only (YYYY-MM-DD) |
| time | time only (HH:MM:SS) |
| datetime | date and time |
Other types
| Type | Stores |
|---|
| boolean | true or false |
| blob | binary data (images, files) |
MySQL notes
- MySQL also has
TINYINT, MEDIUMINT, BIGINT. TEXT, MEDIUMTEXT, LONGTEXT for longer text.TIMESTAMP tracks date+time.
Why types matter
The type determines:
- What values are allowed (text vs numbers).
- How much space each row uses.
- Which functions and comparisons work.
TL;DR
- int for whole numbers, decimal for money.
- varchar(n) for text up to n characters.
- date/datetime for dates and times.
- The right type keeps your data correct.