✏️ Explanatory Question
Level: Basic — Tests whether you can pick the right type for each column, which affects storage and performance.
MySQL data types are grouped into three main categories — Numeric, String (Character), and Date & Time. Choosing the correct type keeps your database efficient and your data accurate.
DECIMAL (not FLOAT/DOUBLE) for money — floating-point types are approximate and can cause rounding errors in financial calculations.
| Type | Storage | Signed Range |
|---|---|---|
| TINYINT | 1 byte | -128 to 127 |
| SMALLINT | 2 bytes | -32,768 to 32,767 |
| INT | 4 bytes | -2.1B to 2.1B |
| BIGINT | 8 bytes | -9.2 quintillion to 9.2 quintillion |
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY, -- numeric
name VARCHAR(100) NOT NULL, -- string
price DECIMAL(10, 2), -- exact money value
category ENUM('Electronics','Books','Food'), -- one from a list
description TEXT, -- large text
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- date & time
launch_date DATE -- date only
);