SQL Query to Insert Multiple Rows
Last Updated :
03 Nov, 2025
The INSERT INTO statement in SQL is used to add new records to a table. It’s a key part of Data Manipulation Language (DML) and allows adding single or multiple rows efficiently, improving database performance.
Example: First, we will create a demo SQL database and table, on which we will use the Insert Multiple Rows command:
Query:
INSERT INTO Employees (EmployeeID, EmployeeName, Age, Department)
VALUES (1, 'John Doe', 30, 'Engineering');
Output:
Syntax:
INSERT INTO table_name (column1, column2, column3)
VALUES (value1, value2, value3);
How to Insert Multiple Rows in SQL
Insertion is a DML (Data Manipulation Language) operation in SQL used to add data into a database. It can be done using the INSERT statement, either for single or multiple rows. Common methods include simple multi-value inserts, INSERT INTO ... SELECT, or batch inserts using transactions.
Query:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
EmployeeName VARCHAR(100),
Age INT,
Department VARCHAR(50)
);
The simplest method to insert multiple rows is by using a single INSERT INTO statement followed by multiple sets of values. This approach allows you to insert multiple records in one go, improving efficiency.
INSERT INTO Employees (EmployeeID, EmployeeName, Age, Department)
VALUES
(1, 'John Doe', 30, 'Engineering'),
(2, 'Jane Smith', 28, 'Marketing'),
(3, 'Sam Brown', 35, 'Sales'),
(4, 'Lucy Green', 25, 'Human Resources');
Output:
Insert Multiple RowsThis query inserts four rows into the Employees table. It’s a simple, effective method for adding multiple records at once, and it reduces the need for multiple INSERT statements.
Using INSERT INTO ... SELECT for Inserting Multiple Rows
The INSERT INTO ... SELECT method is useful when you need to insert multiple rows into a table based on the results of another query or a different table. This method is often used for transferring data between tables or inserting derived data into a target table.
NewEmployees table
CREATE TABLE NewEmployees (
EmployeeID INT PRIMARY KEY,
EmployeeName VARCHAR(100),
Age INT,
Department VARCHAR(50)
);
INSERT INTO NewEmployees (EmployeeID, EmployeeName, Age, Department)
VALUES
(5, 'Alice Johnson', 29, 'HR'),
(6, 'Bob Martin', 32, 'Finance'),
(7, 'Charlie Baker', 28, 'Marketing'),
(8, 'David Lee', 40, 'Engineering'),
(9, 'Eva Davis', 22, 'Sales');
Output:
In this example:
- The INSERT INTO ... SELECT statement copies data from the NewEmployees table to the Employees table.
- Only records where the employee’s age is greater than 30 are inserted.
Query:
SELECT EmployeeID, EmployeeName, Age, Department
FROM NewEmployees
WHERE Age > 30;
Output:
Inserting Data Using Transactions
When inserting large amounts of data, you can use SQL transactions to ensure that all rows are inserted correctly. A transaction groups multiple SQL operations into a single unit, so if one operation fails, the entire transaction is rolled back.
Query:
BEGIN TRANSACTION;
INSERT INTO Customers (CustomerID, CustomerName, ContactName, Country)
VALUES (5, 'Sarah White', 'John White', 'Canada');
INSERT INTO Customers (CustomerID, CustomerName, ContactName, Country)
VALUES (6, 'Mohamed Ibrahim', 'Ahmed Ibrahim', 'UAE');
-- If any error occurs, the transaction will be rolled back
COMMIT;
Output:
In this example:
- BEGIN TRANSACTION starts a new transaction.
- COMMIT saves all successful changes permanently to the database.
- If any INSERT fails, ROLLBACK undoes all changes made during the transaction.
- This ensures data consistency and prevents partial data insertion.
SQL Query to Insert Multiple Rows
Explore
Basics
Queries & Operations
SQL Joins & Functions
Data Constraints & Aggregate Functions
Advanced SQL Topics
Database Design & Security