0
0
MySQLquery~5 mins

INSERT INTO multiple rows in MySQL

Choose your learning style9 modes available
Introduction
You use INSERT INTO multiple rows to add many new records to a table in one go. This saves time and makes your work easier.
When you want to add several new customers to your customer list at once.
When you have a list of new products to add to your store's inventory.
When you need to record multiple sales transactions that happened today.
When you want to quickly add several new employees to the company database.
Syntax
MySQL
INSERT INTO table_name (column1, column2, column3) VALUES (value1a, value2a, value3a), (value1b, value2b, value3b), ...;
Each set of values inside parentheses represents one row to add.
Separate each row with a comma.
Examples
Adds two students named Alice and Bob with their ages.
MySQL
INSERT INTO students (name, age) VALUES ('Alice', 20), ('Bob', 22);
Adds three products with their prices in one command.
MySQL
INSERT INTO products (product_name, price) VALUES ('Pen', 1.5), ('Notebook', 3.0), ('Eraser', 0.5);
Sample Program
This creates an employees table, adds three employees at once, then shows all employees.
MySQL
CREATE TABLE employees (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50), department VARCHAR(50));
INSERT INTO employees (name, department) VALUES ('John Doe', 'Sales'), ('Jane Smith', 'Marketing'), ('Emily Davis', 'HR');
SELECT * FROM employees;
OutputSuccess
Important Notes
Make sure the order of values matches the order of columns listed.
If a column can be empty, you can skip it if the table allows NULL or has a default.
Using multiple rows in one INSERT is faster than many single INSERT commands.
Summary
INSERT INTO multiple rows lets you add many records in one command.
Use parentheses for each row and separate rows with commas.
It saves time and makes your database work more efficient.