Primary vs Foreign Keys Workbook (Database Design Lesson 1)
Most students can define a primary key. Fewer can say why a name can't be one, or which side of a relationship the foreign key belongs on. This workbook covers both, in the order an instructor would teach them.
The 3 problems
- Easy: given a student table with unique emails and repeated names, list every candidate key, pick the primary key, and explain why Name fails.
- Medium: one instructor teaches many sections. Where does the foreign key go?
- Hard: with foreign keys turned on, decide which INSERT statements the database will reject, then run them to check.
Details: 16 pages and 8 tested queries. Includes the PRAGMA foreign_keys = ON setup step that SQLite needs and many tutorials skip.
Next in the series: Database Design Lesson 2, Many-to-Many Relationships.