Lesson 9 of 30
30%
INSERT INTO
INSERT INTO adds rows.
You name the table, the columns, and the values.
One row
The VALUES list must match the column list in order and count.
Text goes in quotes. Numbers do not.
sql
Result
Query OK, 1 row affected
Many rows
One INSERT can add several rows. Put a comma between value groups.
sql
Result
Query OK, 3 rows affected
Skip a column
If a column has a DEFAULT, you can leave it out.
If it is NOT NULL with no default, you must give a value.
sql
Result
Query OK, 1 row affected
Check the rows
sql
Result
| id | name | age | city |
|---|---|---|---|
| 1 | Ada | 12 | London |
| 2 | Sam | 11 | Kenya |
| 3 | Lin | 13 | Taipei |
| 4 | Omar | 12 | Cairo |
| 5 | Nia | 10 | Unknown |
5 rows
Tip: List column names in INSERT. Do not rely on table order. Tables change.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.