

- 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 insert multiple rows with single MySQL query?
You can insert multiple rows with the help of values() separated by comma(,). The syntax is as follows −
insert into yourTableName values(value1,value2,...N),(value1,value2,...N),(value1,value2,...N),(value1,value2,...N),(value1,value2,...N),(value1,value2,...N)................N;
To insert multiple rows, let us create a table. The following is the query to create a table −
mysql> create table MultipleRowsInsert −> ( −> UserId int, −> UserName varchar(200) −> ); Query OK, 0 rows affected (1.21 sec)
Here is the query to insert multiple rows in the table −
mysql> insert into MultipleRowsInsert values(100,'Bob'),(101,'Smith'),(102,'Carol'),(104,'David'),(105,'Sam'); Query OK, 5 rows affected (0.33 sec) Records: 5 Duplicates: 0 Warnings: 0
Display all the records using the SELECT −
mysql> select *from MultipleRowsInsert;
The following is the output −
+--------+----------+ | UserId | UserName | +--------+----------+ | 100 | Bob | | 101 | Smith | | 102 | Carol | | 104 | David | | 105 | Sam | +--------+----------+ 5 rows in set (0.00 sec)
- Related Questions & Answers
- Insert multiple rows in a single MySQL query
- How to obtain multiple rows in a single MySQL query?
- How to get multiple rows in a single MySQL query?
- 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 do I insert multiple values in a column with a single MySQL query?
- MySQL query to insert multiple records quickly
- Update multiple rows in a single MongoDB query?
- How to insert multiple rows in a table using a single INSERT command in program?
- MySQL query to select multiple rows effectively?
- Count and sort rows with a single MySQL query
- How to sort multiple columns with a single query?
- How to multiple insert or batch insert at a time in MySQL query?
- MySQL query to count rows in multiple tables
- MySQL query to check if multiple rows exist?
Advertisements