Every shelf must belong to an existing room. The rooms table is supplied; create only its child.
These tables are already loaded at the start of this lesson.
roomsOne row represents one room.
| Field / SQL type | Meaning | Rules |
|---|---|---|
room_id · integer | Identifier of the room. | Primary key. Required; cannot be NULL. |
name · text | Room display name. | Nullable; NULL means no name value is recorded. |
The database does not contain these tables yet. The definitions below describe the new tables for this lesson, not tables inherited from an earlier attempt.
shelvesOne row represents one shelf.
| Field / SQL type | Meaning | Rules |
|---|---|---|
shelf_id · integer | Identifier of the shelf. | Primary key. Required; cannot be NULL. |
room_id · integer | Identifier of the shelf's required parent room. | Required; cannot be NULL. Foreign key to rooms.room_id; parent deletion is restricted. |
shelves.room_id matches rooms.room_id. One rooms row can have zero or many matching shelves rows; each shelves row must reference exactly one existing parent. This is a declared foreign key.
Joining child detail repeats the parent fields once per matching child. An inner join omits unmatched rows; a left join keeps unmatched rows from its left input with NULLs for the missing side. Those result NULLs are separate from missing values stored in a real row.
Write your query in script.sql. Use Run to inspect it, then Submit.
Create the child with REFERENCES to the supplied parent table.