- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the fastest way to insert a large number of rows into a MySQL table?
The syntax for the fastest way is given below. Here, we have used INSERT INTO just once and formed an optimized way −
insert into yourTableName values(NULL,yourValue1',yourValue2),(NULL,yourValue1',yourValue2),....N;
Let us first create a table −
mysql> create table DemoTable1839 ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(20), ClientAge int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1839 values(NULL,'Chris',29),(NULL,'Chris',29),(NULL,'Chris',29),(NULL,'Chris',29),(NULL,'Chris',29),(NULL,'Chris',29),(NULL,'Chris',29),(NULL,'Chris',29); Query OK, 8 rows affected (0.00 sec) Records: 8 Duplicates: 0 Warnings: 0
Display all records from the table using select statement −
mysql> select * from DemoTable1839;
This will produce the following output −
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 1 | Chris | 29 | | 2 | Chris | 29 | | 3 | Chris | 29 | | 4 | Chris | 29 | | 5 | Chris | 29 | | 6 | Chris | 29 | | 7 | Chris | 29 | | 8 | Chris | 29 | +----------+------------+-----------+ 8 rows in set (0.00 sec)
- Related Articles
- Fastest way to count number of rows in MySQL table?
- Easiest way to get number of rows in a MySQL table?
- Fastest way to insert with multiple values in a single MySQL query?
- What is the proper way to insert an IF statement into a MySQL query?
- Insert JSON into a MySQL table?
- What is the most efficient way to select a specific number of random rows in MySQL?
- MySQL INSERT INTO SELECT into a table with AUTO_INCREMENT
- How to write MySQL procedure to insert data into a table?
- Auto insert values into a MySQL table in a range?
- How can we insert data into a MySQL table?
- How can we use INSERT() function to insert a new string into the value of a column of MySQL table?
- Which is the fastest way to get a column's maximum value in MySQL?
- How can we insert a new row into a MySQL table?
- MySQL trigger to insert row into another table?
- Fastest way to search for a date from the date records in MySQL

Advertisements