Code Reference

Getting Started with SQL

SQL · Reference cheat sheet

Getting Started with SQL

SQL · Reference cheat sheet


📋 Overview

SQL (Structured Query Language) is how you talk to relational databases: create tables, insert rows, and query data. Dialects (PostgreSQL, MySQL, SQLite, SQL Server) share a core language with small differences.

🔧 Core concepts

IdeaMeaning
DatabaseNamed collection of schemas/tables
TableRows + named columns
Row / recordOne entry
Column / fieldOne attribute with a data type
QueryStatement that reads or changes data
Primary keyUniquely identifies a row

Beginners often practice on SQLite (a file DB) or a free Postgres instance.

💡 Examples

SQLite quick start:

sqlite3 practice.db
SELECT 'Hello, SQL!' AS message;

Create a tiny table and query it:

CREATE TABLE friends (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL
);

INSERT INTO friends (name) VALUES ('Ada'), ('Grace');
SELECT * FROM friends;

Filter rows:

SELECT name
FROM friends
WHERE name LIKE 'A%';

⚠️ Pitfalls

  • SQL keywords are case-insensitive by convention; SELECT vs select both work.
  • String quotes are single quotes in standard SQL: 'Ada', not "Ada" (double quotes often mean identifiers).
  • Each dialect has quirks (AUTOINCREMENT, SERIAL, LIMIT vs TOP).
  • Never paste untrusted input into SQL strings — use parameterized queries in apps.

On this page