Back to subject
MySQL/INSERT

Add Real Rows to an Empty Table

Practical lesson

Let's add data to the students table we created earlier and read the result back.

INSERT INTO students (id, name, age) VALUES (1, "Ali", 16), (2, "Sara", 17); adds two rows in a single statement. Notice the column list (id, name, age) matches the order of every value group that follows it.

Query OK, 2 rows affected confirms exactly two rows were added this count is a useful sanity check; if you expected to insert 5 rows and it says 2, something in your statement needs a second look.

SELECT * FROM students; then reads every column (that's what * means: all columns) for every row currently in the table, letting you visually confirm the insert worked exactly as intended.

This insert-then-select pattern add data, then immediately look at it is one of the most common habits in everyday database work, especially while you're still learning to trust your own queries.

Try it yourself
Code

Starter example

Code
INSERT INTO students (id, name, age) VALUES
(1, "Ali", 16),
(2, "Sara", 17);
SELECT * FROM students;
Live preview
Query OK, 2 rows affected

+----+------+-----+
| id | name | age |
+----+------+-----+
| 1  | Ali  | 16  |
| 2  | Sara | 17  |
+----+------+-----+
2 rows in set