sql · level 1 · unit 6 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Name the columns, and the values follow that order.
Remembering the order of every column is hard. Instead, put a in brackets after the table name. The values then go in that order, whatever order the table uses.
Leave a column out of the list and its box is filled with NULL. That is handy when you do not know a value yet.
You can add several rows in one go. Put each row's values in their own brackets, with commas between the brackets.
INSERT INTO books (title, pages) VALUES ('Owl Post', 64);
SELECT * FROM books WHERE title = 'Owl Post'; With a column list, the values must follow the order of the list, not the table.
guess first
Only two columns filled. What does the new row hold?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
INSERT INTO pets (name, species) VALUES ('Ziggy', 'snake');
SELECT * FROM pets WHERE name = 'Ziggy';
your turn
Your turn. Add two snacks at once.
Fill in a name and a price, in pence, for each new snack. Both rows go in with one INSERT, and the SELECT finds them because their kind is empty.
result
Your answer appears here as a table.
fix it
The title and the pages swapped places. Fix it!
result
Your answer appears here as a table.
- The new book cannot be found by its title. What went into the title box?
- The values go in the same order as the column list: title first, then pages.
- Swap the values so 'Owl Post' comes first and 64 second, then press run.
nailed it
you filled in exactly the columns you meant. :D
- A column list says which columns your values go into.
- Columns left out get
NULL. - Add several rows at once, each in its own brackets.
new words in your collection
- column list
This lesson isn’t saved. A free account remembers every lesson you finish.