Open lesson

Mission: prepare Imani’s lab

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

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

  1. Name both tables, their main columns and types.
  2. Show each table’s primary key and how the foreign key links them.
  3. Explain what ALTER TABLE adds and the only situation in this exercise where DROP TABLE is acceptable.
  4. Predict whether A1 and A2 with the same event_key are forbidden by this schema, then say what the prediction cannot prove.

How to check your work

  • vehicles.code and authorization columns id, vehicle_code, actor_id, event_key, attempt_no are described correctly.
  • Both unique IDs and link vehicle_code → vehicles.code are explained.
  • source_file is added on the copy; only throwaway_notes is 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;

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with -- are task reminders. SQL ignores them. Write your query beneath them.

SQL console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.sql

Current editor source. Inspection shows your current edits.

-- Name both tables, their main columns and types.
-- Show each table’s primary key and how the foreign key links them.
-- Explain what `ALTER TABLE` adds and the only situation in this exercise where `DROP TABLE` is acceptable.
-- Predict whether A1 and A2 with the same `event_key` are forbidden by this schema, then say what the prediction cannot prove.

exemple.sql

Declarative lesson asset; this is not a file created in the Python filesystem.

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;