SQL Advanced Recap — Constraints, Design, and Tuning at a Glance

A recap of the SQL Advanced series. Cross-reference advanced UPDATE/DELETE and UPSERT, constraints and foreign keys, type affinity and STRICT, normalization and views, and index design and tuning starting from EXPLAIN QUERY PLAN — with diagrams and an article index.

The big picture of what you learned in SQL Advanced

This page pulls the SQL Advanced series together on a single page, viewed through three lenses: constraints and design that keep data safe, a readable, correct schema, and indexes and tuning for fast queries.

After picking up the grammar in the Basics and aggregation, joins, and window functions in the Intermediate series, Advanced was about keeping data correct and making it run fast — design and tuning.

Use the links to any article to jump back for review anytime.

The big picture of what SQL Advanced lets you do
MoveAdvanced UPDATE / DELETE / UPSERTKeep correctConstraints / FKs / typesOrganizeNormalization / views / designRead the planEXPLAIN / stats / joinsSpeed upIndex designprotectorganizemeasureimprove
Move data with advanced DML, keep it correct with constraints, foreign keys, and types, organize the schema with design, and speed queries up with execution plans and indexes.

Keeping data correct — advanced writes, constraints, foreign keys, types, design

We covered advanced UPDATE / DELETE and UPSERT with subqueries and joins, column constraints and foreign keys, type affinity and STRICT, and on to normalization, views, and design practice.

The diagram below groups the advanced DML and constraints/types together, and the design/views together.

The 11 articles on advanced writes, constraints, types, and design
Advanced writesMoveUPDATE / DELETEapplicationsUPSERTON CONFLICTConstraints / typesKeep correctConstraints / FKsconstraint changesType affinitySTRICT / datesDesignOrganizeNormalization1NF to 3NFViewsdesign practice
Move data with advanced writes, protect its correctness with constraints, foreign keys, and types, and organize the schema with normalization, views, and design practice.
CategoryArticleWhat you learn
Advanced writesUPDATE / DELETE with Subqueries and JOINsCorrelated updates, UPDATE … FROM, DELETE with subquery conditions
Advanced writesUPSERT (ON CONFLICT) and Bulk INSERT ApplicationsINSERT … ON CONFLICT DO UPDATE, excluded, bulk INSERT
ConstraintsColumn Constraints — NOT NULL / UNIQUE / CHECK / PRIMARY KEYNOT NULL / UNIQUE / CHECK / PRIMARY KEY and violations
Foreign keysForeign Key Constraints and Referential ActionsREFERENCES, ON DELETE / UPDATE, foreign_keys=ON
Constraint changesAdding/Changing Constraints and Table RedefinitionRetrofitting constraints, the table-rebuild procedure
TypesStrings, Numbers, Booleans and Implicit Type ConversionType affinity, implicit conversion, vs. strict types
TypesDate/Time Types and STRICT TablesStoring and comparing date/time, STRICT tables
DesignTable Design and Normalization1NF to 3NF, removing repeating columns, 3-tier schema
DesignViews (VIEW)CREATE VIEW, using views, updatable views

Making queries fast — execution plans, indexes, tuning

Read plans with EXPLAIN QUERY PLAN, understand statistics, the optimizer, and join algorithms, get a handle on index design, index-only scans, indexing for sorts and groups, and the patterns where indexes don't kick in, then finish with query rewrites.

The table below organizes each article.

CategoryArticleWhat you learn
Execution planReading Execution PlansVocabulary: SCAN / SEARCH / USE TEMP B-TREE and more
StatisticsStatistics and the OptimizerANALYZE, sqlite_stat1, selectivity and plan changes
JoinsJoin Algorithms and Join OrderNested loop, join order, automatic indexes
IndexesIndexes — Composite, Partial, Expression, UNIQUEComposite, partial, expression, UNIQUE indexes with EXPLAIN
IndexesIndex DesignComposite column order, leftmost prefix, conditions that use the index
IndexesIndex-Only ScanIndex-only scan, USING COVERING INDEX
IndexesIndexing ORDER BY / GROUP BYAvoiding USE TEMP B-TREE, indexing sorts and groups
IndexesWhen Indexes Don't Kick InFunctions on columns, implicit casts, LIKE, OR, and expression/partial index fixes
RewritesQuery Rewrites ① IN / EXISTS and decorrelationIN vs EXISTS, removing correlation, semi-join / anti-join
RewritesQuery Rewrites ② removing repeated work, worked examplesEliminating repeated work, subquery optimization with examples

Nice work!

By now you've pulled together advanced UPDATE / DELETE and UPSERT, the design side with constraints, foreign keys, types, normalization, and views, and the tuning side with index design and more, starting from EXPLAIN QUERY PLAN.

This also marks the finish of all three tiers of the SQL course — Basics, Intermediate, and Advanced.

Great job making it all the way through.

Head back to any article that caught your eye and keep experimenting with your own data.