 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
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)
Advertisements
 