← Lesson
BitWithBite
SQL · Quick Reference

Lesson 3 — Data Types & Constraints Cheat Sheet

SQL
In one line: Choose the right numeric type to balance precision and storage efficiency.

Key Ideas

1Numeric Types. Choose the right numeric type to balance precision and storage efficiency.

Code Examples

-- CHAR: fixed-length (padded with spaces) country_code CHAR(2) -- always exactly 2 chars: 'PK', 'US' -- VARCHAR: variable-length (efficient) name VARCHAR(100) -- stores only actual length + 1 byte -- TEXT: for long content (up to 6...
-- DATE: stores date only (YYYY-MM-DD) birthday DATE -- '2006-03-15' -- DATETIME: date + time (YYYY-MM-DD HH:MM:SS) appointment DATETIME -- '2026-06-18 14:30:00' -- TIMESTAMP: like DATETIME but auto-converts timezone created_at...
CREATE TABLE orders ( id INT PRIMARY KEY AUTO_INCREMENT, customer_id INT NOT NULL, total DECIMAL(10,2) NOT NULL CHECK (total >= 0), status VARCHAR(20) DEFAULT 'pending', order_date DATE NOT NULL, UNIQUE (customer_id...