INSERT INTO example
The operation runs inside a practice transaction. One row includes an email and the other leaves that value as NULL.
BEGIN;
INSERT INTO customers
(id, name, email, city, registered_at, active)
VALUES
(90, 'Nora Paz', 'nora@example.test', 'Oxford', '2026-08-05', 1),
(91, 'Oscar Moon', NULL, 'Cambridge', '2026-08-05', 1);
SELECT id, name, email, city, active
FROM customers
WHERE id IN (90, 91)
ORDER BY id;
ROLLBACK;ROLLBACK returns the practice copy to its original state. In a real application, let the engine generate the identity when the column is set up for it, instead of making up identifiers by hand.
Check the result with small data
We create a test table and add two customers explicitly.
CREATE TABLE demo_customers (id INTEGER, name TEXT);
INSERT INTO demo_customers (id, name)
VALUES (1,'Amy'),(2,'Liam');
SELECT id, name FROM demo_customers ORDER BY id;| id | name |
|---|---|
| 1 | Amy |
| 2 | Liam |
INSERT INTO adds rows; it does not create new columns. Listing the column names avoids relying on their physical order in the table.
Check your understanding: What result would you get if you inserted a third row as well?
Show answer
The SELECT would return three rows: the new one would appear next to Amy and Liam, in the position it gets when sorted by id.
How INSERT INTO is used
List the columns. Do not rely on the table's physical column order. If the schema changes or a column has a default value, the intent of the statement stays clear.
What changes from case to case
Columns missing from the list get their DEFAULT or NULL value if the table allows it. If a column is required and has no default, the statement fails, and that error protects the consistency of the data.
Common mix-ups with INSERT INTO
Misaligning columns and values
INSERT INTO products (name, price, stock)
VALUES ('Webcam', 6, 59.90);The statement can be valid yet store 6 as price and 59.90 as the stock. Read columns and values side by side and use constraints that reject impossible combinations.