Designing Databases Lesson 4 of 13
MySQL Data Types — Choosing the Right Type
Choose MySQL data types for numbers (INT, TINYINT, DECIMAL), text (CHAR, VARCHAR, TEXT), dates (DATE, DATETIME, TIMESTAMP), booleans and ENUM, with Philippine examples.
Every column has a data type. The right type saves space, keeps data valid and makes queries faster. The wrong type causes bugs, like money that loses centavos or phone numbers that lose their leading zero.
Whole numbers
| Type | Range (signed) | UNSIGNED range | Use for |
|---|---|---|---|
TINYINT | −128 to 127 | 0 to 255 | Grade level, age, quarter |
SMALLINT | about ±32,000 | 0 to 65,535 | Year, small counts |
INT | about ±2.1 billion | 0 to about 4.2 billion | IDs, quantities |
BIGINT | huge | huge | Very large IDs, amounts in centavos |
UNSIGNED means no negative values, which doubles the positive range. Use it for IDs, quantities and ages.
Decimal numbers
| Type | Exact? | Use for |
|---|---|---|
DECIMAL(10,2) | Yes | Money: up to 10 digits, 2 after the point (99,999,999.99) |
DECIMAL(5,2) | Yes | Grades like 95.25 |
FLOAT, DOUBLE | No (approximate) | Measurements, science data |
Text
| Type | Max length | Use for |
|---|---|---|
CHAR(n) | n characters, fixed | Always the same length: LRN CHAR(12), CHAR(2) codes |
VARCHAR(n) | up to n characters | Names, emails, addresses |
TEXT | about 65,000 characters | Long messages, descriptions |
MEDIUMTEXT, LONGTEXT | 16 MB, 4 GB | Articles, large content |
Phone numbers, LRNs, ZIP codes and TIN numbers are text, not numbers: they can start with 0, you never do math with them, and 09171234567 as an INT would become 9171234567.
Dates and times
| Type | Format | Use for |
|---|---|---|
DATE | 2026-12-25 | Birthdays, due dates |
TIME | 07:30:00 | Class schedules |
DATETIME | 2026-12-25 07:30:00 | Event start times, appointments |
TIMESTAMP | same format | "Created at" / "updated at" (stored in UTC, auto-fill) |
YEAR | 2026 | School year start, model year |
MySQL always uses the YYYY-MM-DD format. Converting "12/25/2026" style input is done in your PHP code or with STR_TO_DATE.
Booleans and ENUM
CREATE TABLE enrollments (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
strand ENUM('STEM', 'ABM', 'HUMSS', 'GAS', 'TVL-ICT') NOT NULL,
is_paid BOOLEAN NOT NULL DEFAULT FALSE,
sex ENUM('M', 'F') NOT NULL
);
BOOLEANis reallyTINYINT(1):TRUEis 1,FALSEis 0.ENUMallows only the listed values. It's convenient for short, fixed lists, but adding an option later requiresALTER TABLE. For lists that change (like sections), use a separate table instead.
A well-typed table
CREATE TABLE products (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
barcode VARCHAR(20) UNIQUE,
name VARCHAR(100) NOT NULL,
price DECIMAL(10,2) NOT NULL CHECK (price >= 0),
stock INT UNSIGNED NOT NULL DEFAULT 0,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
added_on DATE NOT NULL DEFAULT (CURRENT_DATE)
);
Quick decision guide
| Data | Type |
|---|---|
| ID | INT UNSIGNED AUTO_INCREMENT |
| Price, salary, balance | DECIMAL(10,2) |
| Grade | DECIMAL(5,2) or TINYINT UNSIGNED |
| Name, email | VARCHAR(100) |
| Mobile number, LRN | VARCHAR(15), CHAR(12) |
| Yes/no | BOOLEAN |
| Birthday | DATE |
| When a row was created | TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04