CodingNic

CRUD Operations

Inserting Multiple Rows

CRUD Operations 6 min read

Inserting Multiple Rows

Objectives

By the end of this lesson, you should be able to:

  • Insert several rows in a single INSERT statement
  • Explain why this is preferable to separate INSERT statements for each row

💡 Why this matters: Loading a batch of records one INSERT at a time works, but it’s slower and more verbose than it needs to be. A single statement can add many rows at once.

⚠️ A note on verification: every statement and result in this lesson was run against a real, live PostgreSQL 18 database, using the employees table from Module 3.

Multiple VALUES

Separate each row’s values with a comma, inside its own parentheses:

sql
INSERT INTO employees (first_name, last_name, email, department, salary) VALUES
    ('Jordan', 'Reyes', 'jordan.reyes@example.com', 'Sales', 62000),
    ('Priya', 'Shah', 'priya.shah@example.com', 'Marketing', 58000);
text
 id | first_name | department  | salary
----+------------+-------------+---------
  2 | Jordan     | Sales       | 62000.00
  3 | Priya      | Marketing   | 58000.00

This is one statement, not two, every row is validated and inserted together. The column list at the top applies to every row that follows, there’s no need to repeat it.

Why This Is Better Than One Row at a Time

Sending ten separate INSERT statements to add ten rows works, but each one is a separate round trip to the database. A single multi-row INSERT sends all ten rows together, faster, and shorter to write and read.

Try It

  1. Insert three new employees in a single INSERT statement.
  2. Confirm all three were added by selecting from employees.
  3. Explain, in your own words, why a single multi-row INSERT is generally preferable to several single-row INSERT statements.

Recap

  • Separating rows with commas, each in its own parentheses, inserts several rows in one statement.
  • The column list is written once and applies to every row.
  • A multi-row INSERT is faster and more concise than repeating single-row INSERT statements.

Next lesson: INSERT ... SELECT, populating a table from the result of a query instead of literal values.