Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn 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:

sql

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:

sql

In this case the query will look like this:

sql

Demonstration:

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 6

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

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:

sql

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:

sql

In this case the query will look like this:

sql

Demonstration:

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 6
some-alt