======================================================================
 DB::Handy SQL Cheat Sheet
======================================================================

[ Data Types ]
  INT          : Integer
  FLOAT        : Floating point number
  VARCHAR(n)   : Variable-length string (max n bytes)
  CHAR(n)      : Fixed-length string (always n bytes)

[ 1. CREATE / DROP (Create and Drop tables) ]
  CREATE TABLE student (id INT PRIMARY KEY, name VARCHAR(20), score INT);
  DROP TABLE student;

[ 2. INSERT (Add data) ]
  -- Add data specifying columns (Recommended)
  INSERT INTO student (id, name, score) VALUES (1, 'Alice', 85);
  -- Add data without specifying columns
  INSERT INTO student VALUES (2, 'Bob', 70);

[ 3. SELECT (Search data) ]
  -- Get all data
  SELECT * FROM student;
  -- Specify conditions (WHERE)
  SELECT name, score FROM student WHERE score >= 80;
  -- Sort data (ORDER BY)
  SELECT * FROM student ORDER BY score DESC;
  -- Limit the number of rows (LIMIT)
  SELECT * FROM student ORDER BY score DESC LIMIT 3;

[ 4. UPDATE (Update data) ]
  UPDATE student SET score = 90 WHERE id = 1;

[ 5. DELETE (Delete data) ]
  DELETE FROM student WHERE id = 2;

[ Operators ]
  Comparison: =, <>, !=, >, <, >=, <=
  Range     : BETWEEN 70 AND 90
  List      : IN (1, 2, 3) or NOT IN (1, 2, 3)
  String    : LIKE 'A%' (Starts with A), LIKE '%A' (Ends with A)
  NULL check: IS NULL, IS NOT NULL
  Logical   : AND, OR, NOT

[ Aggregate Functions ]
  COUNT(*) : Count the number of rows
  SUM(col) : Calculate the sum
  AVG(col) : Calculate the average
  MAX(col) : Find the maximum value
  MIN(col) : Find the minimum value
  (Example) SELECT COUNT(*), AVG(score) FROM student;

[ Indexes (Speed up queries) ]
  CREATE INDEX idx_score ON student (score);
  CREATE UNIQUE INDEX uq_name ON student (name);
======================================================================
