Brief
Design two practice tables with columns and simple rules, then explain what their shape prevents and what it cannot guarantee.
In the story, Mara has a few minutes before Voss presents two rows against you. Imani gives you a fresh SQLite database clearly marked PRACTICE COPY. She wants vehicle and authorization tables, a place for a source file and an explanation of possible duplication. Originals remain outside the lab.
Your mission
- Name both tables, their main columns and types.
- Show each table’s primary key and how the foreign key links them.
- Explain what
ALTER TABLEadds and the only situation in this exercise whereDROP TABLEis acceptable. - Predict whether A1 and A2 with the same
event_keyare forbidden by this schema, then say what the prediction cannot prove.
How to check your work
vehicles.codeand authorization columnsid,vehicle_code,actor_id,event_key,attempt_noare described correctly.- Both unique IDs and link
vehicle_code→vehicles.codeare explained. source_fileis added on the copy; onlythrowaway_notesis dropped in the example.- Two different IDs with one event are allowed here; guilt cannot be inferred.
Course example
PRAGMA foreign_keys = ON;
CREATE TABLE vehicles (
code TEXT PRIMARY KEY
);
CREATE TABLE authorizations (
id TEXT PRIMARY KEY,
vehicle_code TEXT NOT NULL,
actor_id TEXT NOT NULL,
event_key TEXT NOT NULL,
attempt_no INTEGER NOT NULL,
FOREIGN KEY (vehicle_code) REFERENCES vehicles(code)
);
ALTER TABLE authorizations ADD COLUMN source_file TEXT;
CREATE TABLE throwaway_notes (note TEXT);
DROP TABLE throwaway_notes;