Aral Code

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

TypeRange (signed)UNSIGNED rangeUse for
TINYINT−128 to 1270 to 255Grade level, age, quarter
SMALLINTabout ±32,0000 to 65,535Year, small counts
INTabout ±2.1 billion0 to about 4.2 billionIDs, quantities
BIGINThugehugeVery large IDs, amounts in centavos

UNSIGNED means no negative values, which doubles the positive range. Use it for IDs, quantities and ages.

Decimal numbers

TypeExact?Use for
DECIMAL(10,2)YesMoney: up to 10 digits, 2 after the point (99,999,999.99)
DECIMAL(5,2)YesGrades like 95.25
FLOAT, DOUBLENo (approximate)Measurements, science data

Text

TypeMax lengthUse for
CHAR(n)n characters, fixedAlways the same length: LRN CHAR(12), CHAR(2) codes
VARCHAR(n)up to n charactersNames, emails, addresses
TEXTabout 65,000 charactersLong messages, descriptions
MEDIUMTEXT, LONGTEXT16 MB, 4 GBArticles, 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

TypeFormatUse for
DATE2026-12-25Birthdays, due dates
TIME07:30:00Class schedules
DATETIME2026-12-25 07:30:00Event start times, appointments
TIMESTAMPsame format"Created at" / "updated at" (stored in UTC, auto-fill)
YEAR2026School 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
);
  • BOOLEAN is really TINYINT(1): TRUE is 1, FALSE is 0.
  • ENUM allows only the listed values. It's convenient for short, fixed lists, but adding an option later requires ALTER 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

DataType
IDINT UNSIGNED AUTO_INCREMENT
Price, salary, balanceDECIMAL(10,2)
GradeDECIMAL(5,2) or TINYINT UNSIGNED
Name, emailVARCHAR(100)
Mobile number, LRNVARCHAR(15), CHAR(12)
Yes/noBOOLEAN
BirthdayDATE
When a row was createdTIMESTAMP DEFAULT CURRENT_TIMESTAMP

Quick Quiz

Check what you learned. Walang grade ito, practice lang. 🙂

1. Which type is best for prices?
2. Why store a mobile number as VARCHAR?
3. What does UNSIGNED do?
4. What format does MySQL use for DATE values?

By Sir Reyel · Last updated 2026-12-04