So far your queries only read the shop's tables. INSERT INTO adds a new row to a table. You write the table's name, then the columns you fill in, in parentheses, then VALUES with the new row's values, in the same order as the columns.
Text values go in single quotes, numbers don't. You leave out id: the database gives the new row the next free number. For example, this adds a bowl to the kitchen products:
INSERT INTO products (name, price, category, stock)
VALUES ('Bowl', 6, 'kitchen', 12);
You don't have to fill in every column. A column you leave out gets its default: in products, stock was made with DEFAULT 0, and category has no default, so it becomes NULL. Two statements in one query are separated by a semicolon.
The check runs your statements, then prints the whole products table. It must print:
id | name | price | category | stock 1 | Mug | 12 | kitchen | 10 2 | Notebook | 7 | office | 0 3 | Lamp | 29 | home | 1 4 | Pen | 2 | office | 120 5 | Plant | 15 | home | 6 6 | Teapot | 22 | kitchen | 4 7 | Stapler | 9 | office | 15 8 | Gift card | 50 | NULL | 999 9 | Candle | 8 | home | 25 10 | Scissors | 4 | NULL | 0 (10 rows)
Your task: in query, add a 'Candle' that costs 8, in the 'home' category, with 25 in stock. Then add 'Scissors' for 4, giving only the name and the price.
Assignment
Follow the Coding Tutorial to write the two INSERT statements in query, one clause per line.
Hint
The values go in the same order as the columns you listed. End each statement with a semicolon, inside the string. Each line of query is a TypeScript string in an array, followed by a comma; .join(" ") joins the lines into one string, with a space between them.
Free plan: 30 tutor messages. PRO is unlimited.
