- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
- Writing a MongoDB insert statement for multiple insert at a time
- How to do a batch insert in MySQL?
- MySQL query to insert multiple records quickly
- MySQL query to select rows one batch at a time
- Insert multiple rows in a single MySQL query
- How to insert multiple rows with single MySQL query?
- 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?
- MySQL - Insert current date/time?
- How to insert current date/time in MySQL?
- Insert with a Select query in MySQL
- How do I insert multiple values in a column with a single MySQL query?
- MySQL query to insert row with date?
- Insert records from multiple tables in MySQL