Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Cheat sheet · Foundations

SQL and databases cheat sheet (PostgreSQL)

Opens with credits

For students and early-career engineers learning SQL on PostgreSQL, from the first SELECT to schema design, transactions, indexes and using SQL safely from application code. Every snippet is PostgreSQL syntax, with psql and pgAdmin as the tools.

Curated by Tauseef Fayyaz9 chapters77 concepts197 glossary terms

Chapters

9 chapters · 77 concepts

  1. 1Relational model and your setupWhat a relational database is, the keys that connect tables, and the server, client and sample data you need before writing real queries.7 concepts
  2. 2Querying one tableSELECT from a single table: choosing columns, filtering rows, handling NULL, sorting, limiting and shaping results with expressions.9 concepts
  3. Joins and set operationsCombining rows from several tables with joins, and combining whole result sets with UNION, INTERSECT and EXCEPT.8 conceptsOpens with credits
  4. Aggregation, subqueries and windowsSummarising rows with GROUP BY, nesting queries with subqueries and CTEs, and calculating rankings and running totals with window functions.11 conceptsOpens with credits
  5. Schema designTurning requirements into tables: entities and relationships, keys, normalisation, data types, constraints and views.9 conceptsOpens with credits
  6. Changing data safelyINSERT, UPDATE, DELETE and upserts, and the transactions, isolation levels and locks that keep concurrent changes correct.9 conceptsOpens with credits
  7. Indexes and query plansHow indexes make reads fast, how to read what the database actually did with EXPLAIN or an execution plan, and the habits that keep queries quick.10 conceptsOpens with credits
  8. SQL in applications and operationsUsing SQL safely from code, keeping schema changes under control, and the operational basics: pools, permissions, backups and where other kinds of database fit.9 conceptsOpens with credits
  9. NoSQL and MongoDBHow a document database compares with the relational model, using MongoDB: documents, queries mapped from SQL, embedding versus referencing, indexes and transactions, and JSON inside your own database.5 conceptsOpens with credits
  10. 10Glossary, A to ZEvery concept in the sheet and the smaller terms it uses, in one list.197 terms

About this sheet

Queries, design, indexes, transactions.

Picked from the other libraries by shared topics.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.

  • 1:1 Mentorship
  • Fresh Graduate Mentorship
  • Career Guidance

Brand deals, promos and partnerships: tauseeffayyaz@gmail.com