Data Types — Complete Guide
Data Types — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 8 of 100
Data Types
Basics → Advanced
Basics · 1 — SQL · ~6 min · MySQL — Foundations
What is this?
Each column has a type: INT for counts, DECIMAL for money, DATE for calendar days, JSON for flexible payloads. Picking the right type saves space and prevents bad data.
Why should you care?
Storing rupee amounts in FLOAT causes rounding errors on GST totals; storing phone numbers in INT drops leading zeros.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
CREATE TABLE IF NOT EXISTS products (
product_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
sku VARCHAR(40) NOT NULL,
price_inr DECIMAL(10,2) NOT NULL,
attrs JSON,
is_active TINYINT(1) NOT NULL DEFAULT 1
);
What happened?
- price_inr uses DECIMAL(10,2) for paise-accurate money.
- attrs is JSON for color/size without ALTER every launch.
- TINYINT(1) acts as boolean for active flag.
Practice next
- Create products table in DataFlow.
- Insert: INSERT INTO products (sku, price_inr, attrs) VALUES ('DF-TSHIRT', 799.00, JSON_OBJECT('size','M','color','blue'));
- Select attrs: SELECT sku, attrs->>'$.color AS color FROM products;
- Change attrs to store an array: JSON_ARRAY('red','blue').
- Use CAST(price_inr AS CHAR) in SELECT and compare display.
Remember
Match types to real data shape. DECIMAL for money, JSON for semi-structured fields. Wrong types cause silent bugs or insert failures.
Flipkart-style SKU attrs
New festival badge lives in products.attrs JSON instead of ten nullable columns.
Outcome: Catalog team ships badges without weekly migrations.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!