Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Inserting Multiple Rows | Populating a Database
Introduction to SQL
course content

Course Content

Introduction to SQL

Introduction to SQL

1. Getting Started
3. Sorting Data
4. Populating a Database
5. Updating & Deleting Data

book
Inserting Multiple Rows

Oftentimes we need to insert more than one row into a table, and re-writing the insert statements many times can be tedious and inefficient. Luckily, SQL provides us with a slightly shorter syntax which basically compresses multiple INSERT statements into a single query.

Following is the general syntax for inserting multiple rows using a single insert statement:

The following example shows the syntax for inserting multiple rows into a table called students which has three columns first_name, second_name and age:

1234567
INSERT INTO students (first_name, second_name, age) VALUES ('Alice', 'Smith', 20), ('Bob', 'Johnson', 22), ('Charlie', 'Brown', 19); SELECT * FROM students;
copy

Tip:

This syntax has a shorter version as well, in which we don't specify the column names:

In this case the query will look like this:

Demonstration:

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 6
We're sorry to hear that something went wrong. What happened?
some-alt