Section 12 · Stage 4: Build Applications
SQL & Database Design
Design tables in MySQL, write SQL from simple queries to joins, window functions and reports, and understand indexes and transactions, then see the same ideas in PostgreSQL.
What you will be able to do
- Install MySQL and run SQL from the mysql client and MySQL Workbench
- Design normalised tables with keys and constraints from a written requirement
- Write queries with filters, sorting, joins, grouping, subqueries and window functions
- Explain how an index speeds up a query and read a query plan with EXPLAIN
- Use transactions and explain ACID with a money-transfer example
- Build the ShopLite store database that later sections turn into an application, and port it to PostgreSQL
What you will learn
12.1Databases & MySQL Setup8 lessons
Why applications store data in a database and how to get MySQL running on your computer.
12.2Creating Tables & Data Types9 lessons
Create tables with the right column types so the database stores data correctly.
- CREATE TABLE and DROP TABLE35 min
- Number types and DECIMAL for money40 min
- Text types: VARCHAR, TEXT, CHAR and ENUM35 min
- Dates, times and booleans35 min
- Auto-generated ids with AUTO_INCREMENT35 min
- Change a table with ALTER TABLE40 min
- Naming, storage engines and character sets35 min
- Practice: tables and data types45 min
- Mini project: college library tables50 min
12.3Keys & Constraints7 lessons
Let the database reject bad data with primary keys, foreign keys and other constraints.
12.4Inserting, Updating & Deleting Data7 lessons
Change the data in your tables safely and see what changed.
12.5Querying Data10 lessons
Read exactly the rows and columns you need with SELECT.
- SELECT columns and aliases35 min
- Filter rows with WHERE40 min
- IN, BETWEEN, LIKE and REGEXP40 min
- NULL values and IS NULL40 min
- ORDER BY and LIMIT40 min
- DISTINCT and CASE expressions40 min
- String functions40 min
- Number and date functions45 min
- Practice: single-table queries50 min
- Mini project: IPL player statistics50 min
12.6Aggregates & Grouping7 lessons
Turn many rows into totals, counts and averages for reports.
12.7Joins9 lessons
Combine data from several tables, the most asked SQL skill in interviews.
- Why data is split across tables, and joins30 min
- INNER JOIN step by step35 min
- LEFT and RIGHT JOIN40 min
- FULL OUTER JOIN and CROSS JOIN40 min
- Self join: employees and managers35 min
- Joining three or more tables40 min
- Finding missing data with LEFT JOIN ... IS NULL35 min
- Practice: joins50 min
- Mini project: railway reservation queries60 min
12.8Subqueries, Views & Window Functions10 lessons
Answer harder questions with queries inside queries, CTEs and ranking functions.
- Subqueries in WHERE35 min
- Subqueries in FROM and SELECT40 min
- EXISTS and NOT EXISTS40 min
- Common table expressions with WITH45 min
- Views: a saved query as a virtual table40 min
- Ranking with ROW_NUMBER, RANK and DENSE_RANK45 min
- Running totals, LAG and LEAD45 min
- Classic SQL interview questions50 min
- Practice: subqueries, views and window functions50 min
- Mini project: coding contest leaderboard60 min
12.9Database Design & Normalisation9 lessons
Turn a requirement into a clean set of tables without duplicate or inconsistent data.
- Entities, attributes and ER diagrams40 min
- One-to-one and one-to-many relationships40 min
- Many-to-many with join tables40 min
- Anomalies and why we normalise40 min
- First normal form (1NF)40 min
- Second and third normal form45 min
- When denormalising is reasonable45 min
- Practice: database design50 min
- Mini project: courier delivery database60 min
12.10Indexes & Query Performance9 lessons
Understand why some queries are slow and how indexes make them fast.
12.11Transactions & ACID8 lessons
Group changes so they all succeed or all fail, even when many users work at once.
- START TRANSACTION, COMMIT and ROLLBACK40 min
- ACID with a bank transfer40 min
- Dirty, non-repeatable and phantom reads45 min
- Isolation levels in MySQL45 min
- Row locks with SELECT ... FOR UPDATE50 min
- Deadlocks: what they are and how to avoid them45 min
- Practice: transactions and concurrency55 min
- Mini project: cinema seat booking60 min
12.12SQL Practice, ShopLite & PostgreSQL7 lessons
Design and query the ShopLite store database that the next sections build on, practise interview SQL, and port the database to PostgreSQL.
- ShopLite project 1: requirements and schema design60 min
- ShopLite project 2: CREATE script and seed data60 min
- ShopLite project 3: business report queries60 min
- Backups with mysqldump and restoring40 min
- SQL interview problem set50 min
- PostgreSQL for MySQL users: what changes45 min
- ShopLite project 4: ShopLite on PostgreSQL60 min
