Lesson 9: Inserting Data

20 min read Beginner Lesson 9 of 12 8.1k learners

Introduction

The INSERT INTO statement is used to add new rows of data into a table. It’s essential for populating tables with information.

Insert a Single Row

Specify column names and provide values for those columns.

SQL
INSERT INTO customers (first_name, last_name, email, city)
VALUES ('Alice', 'Brown', 'alice.brown@email.com', 'Boston');

Insert Multiple Rows

Use a single INSERT statement with multiple sets of values.

SQL
INSERT INTO customers (first_name, last_name, email, city)
VALUES 
('Tom', 'Evans', 'tom.evans@email.com', 'Chicago'),
('Emma', 'Wilson', 'emma.wilson@email.com', 'Seattle');

Insert Data from Another Table

Copy data from one table into another using INSERT ... SELECT.

SQL
INSERT INTO archived_customers (first_name, last_name, email)
SELECT first_name, last_name, email
FROM customers
WHERE city = 'Chicago';

Handling NULL and DEFAULT Values

If a column allows NULL, you can skip it. If a column has a DEFAULT value, it will be automatically applied if not provided.

SQL
INSERT INTO customers (first_name, last_name)
VALUES ('Sam', 'Taylor');

Practice Quiz

Test your knowledge of INSERT statements:

1. Which keyword is used to add new records?
2. Can you insert multiple rows in one statement?
3. What does INSERT ... SELECT do?
4. What happens if you omit a column with a DEFAULT value?
5. Which clause specifies the target table in an INSERT?