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
| Idea | Meaning |
|---|---|
| Database | Named collection of schemas/tables |
| Table | Rows + named columns |
| Row / record | One entry |
| Column / field | One attribute with a data type |
| Query | Statement that reads or changes data |
| Primary key | Uniquely identifies a row |
Beginners often practice on SQLite (a file DB) or a free Postgres instance.
💡 Examples
SQLite quick start:
sqlite3 practice.dbSELECT '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;
SELECTvsselectboth work. - String quotes are single quotes in standard SQL:
'Ada', not"Ada"(double quotes often mean identifiers). - Each dialect has quirks (
AUTOINCREMENT,SERIAL,LIMITvsTOP). - Never paste untrusted input into SQL strings — use parameterized queries in apps.