MySQL Data Types
A data type is a rule for a column.
It says what kind of value may go in that drawer.
Pick the smallest type that still fits. That keeps tables fast and small.
Numbers
INT for whole numbers like 12 or 1000
BIGINT for huge counts
DECIMAL(10, 2) for money
FLOAT only if you accept rounding
Money should be DECIMAL, not FLOAT. Pennies need exact math.
Text
CHAR(n) is a fixed width. VARCHAR(n) is a short string with a max length.
TEXT is for long notes.
These comments do not run. They are notes for you.
Time
DATE for a calendar day
DATETIME for a day and a clock time
TIMESTAMP for a moment MySQL can auto-update
Yes or no
MySQL uses TINYINT(1) for true and false. 1 is true. 0 is false.
BOOLEAN is an alias for that.
Query OK, 0 rows affected
| Field | Type |
|---|---|
| id | int |
| name | varchar(80) |
| price | decimal(8,2) |
| in_stock | tinyint(1) |
| added_on | date |
5 rows
Tip: Start with INT, VARCHAR, DECIMAL, DATE, and BOOLEAN. Add the rest when you need them.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.