

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 do a batch insert in MySQL?
To do a batch insert, we need to use all column names with parenthesis, separated by ‘,’.
Let us see an example. First, we will create a table. The following is the CREATE command to create a table.
mysql> CREATE table MultipleRecordWithValues - > ( - > id int, - > name varchar(100) - > ); Query OK, 0 rows affected (0.88 sec)
The following is the syntax of batch insert.
INSERT into yourTableName values(column1,column2,....N),(column1,column2,....N),(column1,column2,....N),...........N;
Applying the above syntax to insert batch records.
mysql> insert into MultipleRecordWithValues values(1,'John'),(2,'Carol'),(3,'Bob'),(4,'Smith'); Query OK, 4 rows affected (0.16 sec) Records: 4 Duplicates: 0 Warnings: 0
Since 4 rows are affected, it implies that we have inserted records successfully. To check if all records are present in the table, use the SELECT command.
mysql> select *from MultipleRecordWithValues;
The following is the output.
+------+-------+ | id | name | +------+-------+ | 1 | John | | 2 | Carol | | 3 | Bob | | 4 | Smith | +------+-------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- How to multiple insert or batch insert at a time in MySQL query?
- How do I insert a NULL value in MySQL?
- How to batch update MySQL table?
- Using MySQL in Batch Mode
- How do I insert multiple values in a column with a single MySQL query?
- How to form a MySQL Conditional Insert?
- How do we insert/store a file into MySQL database using JDBC?
- How to insert a Python object in MySQL?
- How can we run MySQL statements in batch mode?
- MySQL query to select rows one batch at a time
- How do I insert elements in a Java list?
- How to insert a Python tuple in a MySQL database?
- How to insert an array of values in a MySQL table with a single INSERT?
- How to prevent duplicate INSERT in MySQL?
- How to easily insert datetime in MySQL?
Advertisements