Your Leeds school library gets a new book. How do you add it to the catalogue?
Your school library in Leeds has a new copy of Matilda. You can already search the catalogue, but searching won’t put the book in it. How do you give the book its own row so it shows up next time?
You’ve used select to read rows from a table. Here’s what the Books table holds now. Each row has a title and a book I D. Book I D is the primary key, so each row must have a different one.
Watch the pairs line up. Book I D is first, so one hundred and four goes first. Title is second, so Matilda goes second, in single quotes because it’s text. In an insert statement, each value matches the column in the same position.
This time the column list puts Title first and Book I D second. You’re adding Holes with the number one hundred and five. Pick the pair that puts each value in the right place, uses the right type and gives the book the requested I D.
Start with insert into Books to name the table. Add Book I D and Title in brackets to set the order. Then write values, followed by one hundred and four and Matilda in single quotes. That one pair of brackets after values supplies one new row.
Now add Holes with book I D one hundred and five. The insert statement lists Book I D first and Title second. Pick what goes after values, and remember that a book I D already in the table can’t be used again.
Select Book I D and Title from Books. Filter for book I D one hundred and four. Expect Matilda with that I D. For a loan list, select titles and loan I Ds from both tables. Match book I Ds. Sort loan I Ds descending for largest first, or ascending for smallest first.
On a practice copy, suppose book one hundred and four should be titled The Witches. Update Books, set Title to The Witches and use where to target that I D. If the book is later withdrawn and has no loans, delete from Books with the same where condition.
Back in the original catalogue, the column list is Book I D, then Title. In the top row, the wrong pair puts the title first. The correct pair puts the number first. In the bottom row, one hundred and one already belongs to Wonder. Use an unused key such as one hundred and six.