04-backend-knowledge

SQL

04-backend-knowledge/sql

SQL

Overview

SQL is the language for querying and changing relational data safely and predictably.


Why It Matters

Good SQL helps you debug data issues, design queries, and understand backend bottlenecks.


Core Concepts

  • SELECT reads.
  • INSERT, UPDATE, and DELETE change data.
  • Joins, indexes, and transactions affect correctness and performance.

Mental Models

Think about the shape of the data before writing the query.


Best Practices

  • Start with the simplest query.
  • Be explicit about joins and filters.
  • Verify row counts and execution behavior when needed.

Common Mistakes

  • Writing ambiguous joins.
  • Updating more rows than intended.
  • Ignoring query cost.

Trade-offs

Readable SQL is often better than dense one-liners, especially when debugging.


Decision Framework

NeedPrefer
Filter dataWHERE
Combine tablesJOIN
Keep changes atomicTransaction

Examples

SELECT id, name
FROM users
WHERE active = true;

Checklists

  • Does the query return exactly what I expect?
  • Are joins and filters explicit?
  • Is the write operation safe and bounded?

Senior Engineer Notes

Senior engineers read SQL like code because it is code. The shape of the query matters as much as the result.


Further Reading