
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to multiple insert or batch insert at a time in MySQL query?
You need to use VALUES() with comma separation for multiple insert or batch insert at a time. Use the following syntax that does not produce an invalid MySQL query on insert. The syntax is as follows:
INSERT INTO yourTableName VALUES(yourValue1),(yourValue1),(yourValue2),(yourValue3),(yourValue4),(yourValue5),.......N;
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table addMultipleValues -> ( -> Counter int NOT NULL -> ); Query OK, 0 rows affected (0.60 sec)
Now you can insert batch records in the table using VALUES() with comma separation. The query to insert record is as follows:
mysql> insert into addMultipleValues values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); Query OK, 10 rows affected (0.27 sec) Records: 10 Duplicates: 0 Warnings: 0
Now display all records from the table using select statement. The query is as follows:
mysql> select *from addMultipleValues;
The following is the output:
+---------+ | Counter | +---------+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | +---------+ 10 rows in set (0.00 sec)
- Related Articles
- How to do a batch insert in MySQL?
- Writing a MongoDB insert statement for multiple insert at a time
- MySQL query to insert multiple records quickly
- Insert multiple rows in a single MySQL query
- How to insert multiple rows with single MySQL query?
- MySQL query to select rows one batch at a time
- MySQL query to insert current date plus specific time?
- Fastest way to insert with multiple values in a single MySQL query?
- Insert multiple values in a temporary table with a single MySQL query?
- How to Execute Batch Insert Update in Hibernate?
- How do I insert multiple values in a column with a single MySQL query?
- How to insert current date/time in MySQL?
- Insert with a Select query in MySQL
- MySQL - Insert current date/time?
- MySQL query to insert row with date?

Advertisements