Keys and joins

Rules that keep bad data out, keys that identify and link rows, and joins that bring linked tables back together in a query.

About 6 hours of study

Learning objectives

Lessons

  1. 1

    Keys and constraints

    Rules the DBMS enforces for you: NOT NULL, UNIQUE, CHECK, PRIMARY KEY and FOREIGN KEY, plus what candidate, primary and foreign keys are.

  2. 2

    Joining tables

    Combine rows from several tables: CROSS JOIN pairs everything, INNER JOIN keeps matching pairs, LEFT JOIN keeps every row of the left table, and a self join matches a table with itself.

Module practice

Module quiz

1. What does a PRIMARY KEY guarantee?
2. orders.customer_id REFERENCES customers(id). What does that refuse?
3. Which join keeps every row of the first table?
4. Table A has 3 rows and table B has 4. How many rows does A CROSS JOIN B have?
5. With ON DELETE SET NULL, a department is deleted. What happens to its teachers?
6. A users table has unique id and unique email columns. What are they?
7. How do you list customers who have never placed an order?

‹ Changing and summarising dataAlgebra, subqueries and views ›