Students create a table, choose a type for each column, give it a primary key and fill it with INSERT.
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 8 min · Investigate 6 min · Modify and Make 11 min
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Pairs sketch a table for a lost-property box: the columns, a type for each, and one example row. Swap and check that each row would have its own id.
Choosing columns. Start from a real list on paper and ask what one row is.
| What you will see | A question to ask | The fix |
|---|---|---|
| table playlists already exists | Did you run the CREATE line twice? | Press Reset and run once. |
| A syntax error near a bracket. | Is there a comma between each column, and none after the last? | Commas separate columns. The last column has none. |
| A mismatch of values and columns. | How many columns does the table have? | Give one value for each column. |
One possible solution for each task. Other correct programs are fine.
CREATE TABLE playlists (
id INTEGER PRIMARY KEY,
name TEXT,
owner TEXT,
description TEXT
);
INSERT INTO playlists VALUES (1, 'Road trip', 'Sam', 'Songs for a long drive');
SELECT * FROM playlists;
CREATE TABLE gigs (
id INTEGER PRIMARY KEY,
place TEXT,
price INTEGER
);
INSERT INTO gigs VALUES (1, 'Town Hall', 35);
INSERT INTO gigs VALUES (2, 'The Barn', 20);
SELECT * FROM gigs;
Stretch: Add a second table of your own and join it to the first.
Support: Give the CREATE TABLE and ask students to write the INSERT.
What is a primary key?
A column whose value is different in every row, so each row can be found and pointed at.
Next lesson: link two tables with a key, so a review knows which song it is about.