SQL tutorial
Query and organize relational data.
11 lessonsExamples and guided walkthroughs
Course contents
Programming fundamentals
Database systems
05060708091011
SQL: constraints keep the data valid
Use PRIMARY KEY, NOT NULL, UNIQUE, CHECK, and REFERENCES so the database itself rejects bad rows.
SQL: transactions with COMMIT and ROLLBACK
Move money between two accounts so that both updates happen or neither does.
SQL: normalization removes repeated facts
Split a table that repeats a customer's city on every row into two tables and see why one update is enough.
SQL: subqueries and common table expressions
Compare each row with a group average, and name an intermediate result with WITH.
SQL: window functions for running totals and ranks
Compute a running total and a rank within each group without collapsing the rows.
SQL: views and triggers
Name a reusable query as a view and record price changes automatically with a trigger.
SQL: a unique index and the system catalog
Enforce uniqueness with an index and look up the index in the database's own catalog.