Why this lesson matters
Understand primary keys and reason about it with a concrete relational example. Primary keys give rows stable identity, foreign keys protect references between tables, and relationship cardinality determines where those keys belong.
How to reason about it
- For Primary Keys, the outcome to verify is: Run the statement against sample data and inspect the result before moving to the next case.
- In Primary Keys, keep this failure controlled: Storing related names or labels instead of keys creates duplicates and makes updates unable to preserve referential integrity.
- Primary Keys practice target: Model customer, order and product relationships with keys and identify one-to-many and many-to-many cardinality.
Practical walkthrough
In the Primary Keys walkthrough: Run the statement against sample data and inspect the result before moving to the next case.
example.sqlsql
CREATE TABLE products (
id BIGINT PRIMARY KEY,
sku VARCHAR(40) UNIQUE NOT NULL
);Practice it yourself
Primary Keys exercise
Model customer, order and product relationships with keys and identify one-to-many and many-to-many cardinality.
- Record the expected result before execution
- Test one valid path and one lesson-specific failure path
- Explain in two lines which boundary owns the decision
