Courses / Databases for Backend Interviews / Chapter 9
Module 5 · Structured Query Language · Chapter 9 of 27
SQL Essentials: Tables, Changes, Queries, Joins, Subqueries and Views
Builds on Databases and the DBMS: Catalogues, Schemas and Data Independence, The Relational Model: Relations, Keys, Integrity and Relational Algebra and Normalisation: Anomalies, 1NF to BCNF, and When to Denormalise. Next up: SQL Query Patterns: A Pattern Map and the Practice Schema.
Part 1 · Running SQL and defining tables
Running SQL for this course
SQL is the language almost every relational database speaks, and a handful of statements cover most daily work.
SQL (Structured Query Language) is declarative: you describe the rows you want, and the database decides how to fetch them. Its statements fall into groups. DDL (data definition language) creates and changes tables. DML (data manipulation language) inserts, updates and deletes rows. A query is a SELECT. DCL (data control language) grants and revokes permissions, and transaction statements group changes.
Every result in this chapter comes from PGlite, a PostgreSQL engine compiled to WebAssembly that runs inside Node. The version used here is 0.5.15, which reports PostgreSQL 18.6, and nothing needs installing besides Node and one package. Create a folder and run these commands.
mkdir tiffin cd tiffin npm init -y npm pkg set type=module npm i @electric-sql/pglite@0.5.15 # save show.ts, run.ts and a SQL file, then: node run.ts schema.sql
Two small files do the work. show.ts prints rows as an aligned text table. run.ts reads a SQL file, runs each statement and prints what it returns. Node 24 runs TypeScript files directly, and the project uses ES modules, which the second command above set.