Adding rows with INSERT
Up to now you've only read data. In the Expert tier you'll change it. Every exercise here runs on a fresh copy of Brightwell's tables, so nothing you do can break anything: press Run as often as you like.
INSERT adds rows. Name the columns, then give the values in the same order:
INSERT INTO departments (id, name, cost_centre)
VALUES (9, 'Legal', 'CC900')Several rows at once:
INSERT INTO departments (id, name, cost_centre)
VALUES (9, 'Legal', 'CC900'),
(10, 'Facilities', 'CC910')Always list the columns. INSERT INTO departments VALUES (…) works too, but it silently depends on
the table's column order, which can change.
You can also insert the result of a query. That's how you copy rows into another table:
INSERT INTO orders_archive
SELECT * FROM orders WHERE order_date < '2024-01-01'After changing data, add a SELECT at the end to look at what you did. Separate the statements
with semicolons.