Learn with Abdou

INTERACTIVE LECTURES

Build and change a database

Guided class activity · apply the ideas from the full SQL lessons.

Preparing for Lab 10 · After practice, try the team challenge.

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

Turn an ERD into an executable build order

Step 4 of 9 · Database: Trail Gear: build rehearsal · New dataset: inspect its schema before continuing.

READ & UNDERSTAND

Lab 10 builds your own client database. The original Trail Gear example here is only a rehearsal: gear_types is the parent, items refers to it, stg_items preserves raw file text, and load_audit records each source decision. The actual client ERD and dictionary determine your application tables.

Start with tables that have no foreign-key dependencies, then tables whose parents already exist. Create and load parents before children. A table nobody references is not necessarily a parent: read the direction of each foreign key, not just the diagram layout.

A declaration alone does not prove enforcement. In the SQLite command line, run PRAGMA foreign_keys = ON; and then PRAGMA foreign_keys; in the same connection before loading. Defaults can depend on the build or tool. You cannot turn enforcement on in the middle of a transaction. The browser exercises inspect the finished rehearsal; use the desktop kit and linked DDL workshops to execute changes.

Worked example
SELECT id, name FROM gear_types ORDER BY id;

The parent list contains two seeded lookup rows. Their source is documented in load.sql.

The join checks meaning after the load. It is useful evidence, but an INNER JOIN alone would conceal an orphan; explicitly search for unmatched children too.

Your question

Return i.serial and g.name AS gear_type for every loaded item by joining its declared parent, ordered by i.id.

Explain your evidence

Which table must be seeded first? What invalid insert would prove the relationship is enforced in the loading connection?

Try a query to unlock the worked-answer discussion.

Loading…
Table & column names only · ↑ ↓ choose · Tab insert · Esc dismiss

CURRENT DATABASE

Quick schema · Trail Gear: build rehearsal

Press Esc or click outside to return to your query. PK = primary key · FK = declared foreign key.

This database has no tables yet. Create a table, then reopen the schema to see its columns.

Control Space also opens names. Enter adds a new line. Control or Command Enter runs your query.

Query results

Predict the result, then run your query.

Predict the result, then run your query.

Read-only activity · One statement per run · First 200 rows displayed · Checks compare the complete bounded result, not just this preview.

Explore this query freely in the playground ↗

Check the save status above. Account-saved work is available in My Progress. Explanations are for discussion, not automatically graded. No prerequisite locks.