What is INSERT?
INSERT adds new rows to a table. Use it when you want to add new data.
The Syntax
INSERT INTO table_name (columns)
VALUES (values);Before INSERT
Our students table: (see table below)
students table - Before INSERT
| id | name | age | grade |
|---|---|---|---|
| 1 | Alice | 20 | A |
| 2 | Bob | 22 | B |
| 3 | Charlie | 21 | A |
3 rows
Insert One Row
INSERT INTO students (id, name, age, grade)
VALUES (4, 'David', 23, 'B');After INSERT: (see after insert table below)
students table - After INSERT (David added)
| id | name | age | grade |
|---|---|---|---|
| 1 | Alice | 20 | A |
| 2 | Bob | 22 | B |
| 3 | Charlie | 21 | A |
| 4 | David | 23 | B |
4 rows
New student David added!
Insert Multiple Rows
Add many rows at once:
INSERT INTO students (id, name, age, grade)
VALUES
(5, 'Emma', 20, 'A'),
(6, 'Frank', 22, 'C');How INSERT Works (Step by Step)
Step 1: Write INSERT INTO
Step 2: Specify table name
Step 3: List columns in ( )
Step 4: Write VALUES
Step 5: Add values in ( ) matching the columns
INSERT INTO students -- Step 1 & 2
(id, name, age) -- Step 3
VALUES (4, 'David', 23); -- Step 4 & 5Quick Reference
INSERT INTO table (cols) VALUES (vals)- Add one rowVALUES (row1), (row2)- Add multiple rows- Column order must match value order
Tip: Always list column names - it's clearer and safer!
Try INSERT
Edit the values and click Run to add a new row
Current Table: students
| id | name | age | grade |
|---|---|---|---|
| 1 | Alice | 20 | A |
| 2 | Bob | 22 | B |
| 3 | Charlie | 21 | A |
3 rows
SQL Editor
Loading...